BulkCopy 之Transaction和dead lock
Posted MichelleDawm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BulkCopy 之Transaction和dead lock相关的知识,希望对你有一定的参考价值。
static object _lock = new object(); public static void _main() { lock (_lock) { _bulkcopy(myData); } } public static void _bulkcopy(DataTable dt) { try { using (var connection = new SqlConnection(ConfigurationSettings.AppSettings.Get("DBConnection"))) { connection.Open(); SqlTransaction transaction = connection.BeginTransaction(); using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction)) { bulkCopy.BatchSize = 100; bulkCopy.BulkCopyTimeout = 100; //default 30 bulkCopy.DestinationTableName = "dbo.MyTable"; try { bulkCopy.WriteToServer(dt); } catch (Exception) { transaction.Rollback(); connection.Close(); } } transaction.Commit(); } } catch { } }
以上是关于BulkCopy 之Transaction和dead lock的主要内容,如果未能解决你的问题,请参考以下文章
Oracle ODP.NET BulkCopy 到临时表问题