I've got some code which uses SqlBulkCopy. And now we're refactoring our code to use Enterprise Library database functions instead of standard ones. The question is how can I instantiate SqlBulkCopy? It accepts SqlConnection, and I only have DbConnection.
var bulkCopy = new SqlBulkCopy(connection) // here connection is SqlConnection
{
BatchSize = Settings.Default.BulkInsertBatchSize,
NotifyAfter = 200,
DestinationTableName = "Contacts"
};
Really easy, we use it like that and it works perfectly :
using (DbConnection connection = db.CreateConnection())
{
connection.Open();
//blah blah
//we use SqlBulkCopy that is not in the Microsoft Data Access Layer Block.
using (SqlBulkCopy copy = new SqlBulkCopy((SqlConnection) connection, SqlBulkCopyOptions.Default, null))
{
//init & write blah blah
}
}
The solution is to cast the connection : (SqlConnection) connection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With