以下代码用于将数据批量插入Azure数据库。在Azure实例中托管时,它无法正常工作。
try
{
SqlCommand truncate = new SqlCommand("truncate table dbo.Dispatch", connection);
truncate.Transaction = transaction;
truncate.ExecuteNonQuery();
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction))
{
bulkCopy.BatchSize = 100;
bulkCopy.DestinationTableName = "dbo.Dispatch";
bulkCopy.WriteToServer(dispatch.AsDataTable());
}
SqlCommand updateHaulerCode = new SqlCommand("exec [sp_UpdateDispatchHaulerCodes]", connection);
updateHaulerCode.Transaction = transaction;
updateHaulerCode.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
}
我想在catch语句中添加日志记录。