Timeout expired with SqlBulkCopy

前端 未结 3 1371
我在风中等你
我在风中等你 2020-12-16 10:06

I\'m using SqlBulkCopy to restore tables from xml backups. One of the table backup is ~200MB large and has a lot of records.

I\'m having error:

Timeo         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 10:25

    There are two ways to fix this error:

    • Increase Timeout by default it is 30 second and 0 means infinite.

         sqlBulkCopy.BulkCopyTimeout = {time in seconds}
      
    • Decrease BatchSize by default it try to insert all rows in one batch

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

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

提交回复
热议问题