如何在Azure Worker角色中添加记录器?

时间:2015-10-27 15:59:39

标签: c# .net azure

以下代码用于将数据批量插入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语句中添加日志记录。

0 个答案:

没有答案