Skip to content

Commit d30b584

Browse files
Issue MikaelEliasson#12: Make SqlBulkCopy reuse connection to avoid credentials problem
1 parent 89ffc91 commit d30b584

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

EntityFramework.Utilities/EntityFramework.Utilities/SqlQueryProvider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ public void InsertItems<T>(IEnumerable<T> items, string schema, string tableName
5050
{
5151
using (var reader = new EFDataReader<T>(items, properties))
5252
{
53-
using (SqlBulkCopy copy = new SqlBulkCopy(storeConnection.ConnectionString, SqlBulkCopyOptions.Default))
53+
var con = storeConnection as SqlConnection;
54+
if (con.State != System.Data.ConnectionState.Open)
55+
{
56+
con.Open();
57+
}
58+
using (SqlBulkCopy copy = new SqlBulkCopy(con))
5459
{
5560
copy.BatchSize = Math.Min(reader.RecordsAffected, 15000); //default batch size
5661
if (!string.IsNullOrWhiteSpace(schema))

0 commit comments

Comments
 (0)