Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout on SqlBulkCopy in Azure

We're having an issue with SqlBulkCopy in Azure.

Context is as follow: We have a table with approximately 10 million rows. Each row has about 15 columns.

We're migrating that data into our new model and this requires a split of the data so 1 row with 15 columns becomes 15 rows.

It worked perfectly in the beginning. The target table now contains 17 767 235 rows and it went quite fast.

At this point, it started to throw exceptions.

I made some modifications to increase the timeout and use batch but it seems like it's totally blocked.

Here is the original exception:

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)
like image 788
Georges Legros Avatar asked Oct 21 '22 08:10

Georges Legros


1 Answers

SQL Azure is very good at protecting itself. This results in throttling and even disconnections. Standard bulk copy techniques with lots of data usually fail. I highly recommend you read Alexandre Brisebois's blog post about Azure bulk copy techniques:

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

like image 131
CSharpRocks Avatar answered Oct 23 '22 03:10

CSharpRocks