我SqlBulkCopy
用来插入大量数据:
try
{
using (var bulkCopy = new SqlBulkCopy(connection))
{
connection.Open();
using (var tran = connection.BeginTransaction(IsolationLevel.ReadCommitted))
{
bulkCopy.DestinationTableName = "table";
bulkCopy.ColumnMappings.Add("...", "...");
using (var dataReader = new ObjectDataReader<MyObject>(data))
{
bulkCopy.WriteToServer(dataReader);
}
tran.Commit();
return true;
}
}
}
catch (Exception ex)
{
return false;
}
但我总是得到例外:
Unexpected existing transaction.
为什么会发生此异常?