Azure中的SqlBulkCopy超时

时间:2014-05-09 16:40:34

标签: c# azure azure-sql-database azure-worker-roles sqlbulkcopy

我们在Azure中遇到SqlBulkCopy问题。

上下文如下:我们有一个大约有1000万行的表。每行有大约15列。

我们正在将这些数据迁移到我们的新模型中,这需要拆分数据,因此包含15列的1行变为15行。

一开始就完美无缺。目标表现在包含17 767 235行,并且速度非常快。

此时,它开始抛出异常。

我做了一些修改以增加超时并使用批处理,但似乎它完全被阻止了。

这是最初的例外:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
The statement has been terminated.; TraceSource 'WaWorkerHost.exe' event Services.DataMigration.Edmi_IN_0   5/9/2014 2:44 PM    2   1508    280

      at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlBulkCopy.RunParser(BulkCopySimpleResultSet bulkCopyHandler)
   at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsyncContinuedOnSuccess(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsyncContinued(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsync(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet internalResults, CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalAsync(CancellationToken ctoken)
   at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32 columnCount, CancellationToken ctoken)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table, DataRowState rowState)

1 个答案:

答案 0 :(得分:3)

SQL Azure非常善于保护自己。这导致节流甚至断开。具有大量数据的标准批量复制技术通常会失败。我强烈建议您阅读Alexandre Brisebois关于Azure批量复制技术的博客文章:

http://alexandrebrisebois.wordpress.com/2013/02/16/using-sqlbulkcopy-to-insert-massive-amounts-of-data-into-windows-azure-sql-database/