I'm using SqlBulkCopy
and System.Data.Datatable
to insert data into my database. I'm doing something like this:
var table = new DataTable();
// Creating table schema
var newRow = table.NewRow();
newRow["FirstName"] = Parser.Parse(values[0])
newRow["LastName"] = Parser.Parse(values[1])
...
newRos["SSN"] = //here I need to encrypt by db certificate value[5] before set it to this row value
And simple copy to db code:
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction))
{
bulkCopy.BatchSize = 100;
bulkCopy.DestinationTableName = "dbo.Member";
try
{
bulkCopy.WriteToServer(table);
}
catch (Exception)
{
transaction.Rollback();
connection.Close();
throw;
}
}
Of course I can set encrypted column later using a stored procedure in the database, but I want to do this in one transaction. Is it possible to encrypt string
value using my certificate from the database in code?
Thanks in advance!