Question

I am using VSTS 2008 + C# + .Net 3.5 + ADO.Net to develop a console application to do bulk insert copy.

I want to use both bulk insert batch and bulk insert timeout property. For the BulkCopyTimeout property, I am confused and want to know whether it applies for the whole bulk or applies to only each batch of the bulk?

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.bulkcopytimeout.aspx

thanks in advance, George

Was it helpful?

Solution

Searching and reading some blog postings and forum posts on the web appears to indicate the the SqlBulkCopyTimeout actually does apply not to the entire operation, but to each batch in the operation.

The MSDN docs isn't totally clear on this, but most posts seem to indicate that the timeout applies to the batch. Decreasing the batch size and/or increasing the SqlBulkCopyTimeout seems to be the solution to timeout problems in most cases.

See this forum post as an example.

Marc

OTHER TIPS

BulkCopyTimeout: By default it is 30 second

sqlBulkCopy.BulkCopyTimeout = {time in seconds for one batch}

BatchSize: By default whole data source is one batch

sqlBulkCopy.BatchSize  = {no of rows you want to insert at once}

For more detail see this link:Timeout expired with SqlBulkCopy

We get this exception "Timeout expired." if application unable to insert the data source in 30 sec.

It applies to the entire operation for one batch. You have to make sure your connections timeout is set as well. I've hit the timeout before, set it on the bulk copy and found out the hard way that the connection time out matters also.

It seems that it's concept of entire operation is funny. If it ends up waiting for more than the timeout at any one time it will fail. In other words if the read of a batch takes more than the time out it will fail, but if the sum of all the reads is > timeout you're okay. If the write of a batch takes too long it will also fail.

But it seems to be batch by batch, not the whole thing.

It's not easy to find the ideal timeout for the bulkcopy; if you choose a small Timeout, you should not select a big batchSize, because timeout errors could occur. On another side, if you decide to choose a small batch-size, you have less chance to have a timeout error from the server; however, you are not secure.

My recommendation is to set the timeout to unlimited, namely (sqlBulkCopy.BulkCopyTimeout = 0), and try to choose a considerable batch-size for your Bulk-copy. At least, you can not have timeout excepection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top