How to make SqlBulkCopy work with MS Enterprise Library?

I have code that uses SqlBulkCopy. And now we are reorganizing our code to use the functions of the Enterprise Library database instead of the standard ones. The question is, how can I create an instance of 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" }; 
+4
source share
1 answer

Really easy, we use it just fine:

 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 pass the connection: (SqlConnection) connection

+7
source

All Articles