SQL SqlBulkCopy 超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4535536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:41:21  来源:igfitidea点击:

Timeout expired with SqlBulkCopy

.netasp.netsqlsql-serversqlbulkcopy

提问by HasanG

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

我正在使用 SqlBulkCopy 从 xml 备份中恢复表。其中一个表备份是~200MB 大并且有很多记录。

I'm having error:

我有错误:

Timeout expired.
The timeout period elapsed prior to completion of the operation or the server
is not responding.

回答by Abdul Saboor

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}
    
  • 增加超时默认为 30 秒,0 表示无限。

       sqlBulkCopy.BulkCopyTimeout = {time in seconds}
    
  • 默认情况下减少 BatchSize 它尝试插入一批中的所有行

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

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

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

回答by Mark Byers

You probably need to increase the timeout. Try increasing the value of sqlBulkCopy.BulkCopyTimeoutfrom the default which is 30 seconds.

您可能需要增加超时时间。尝试增加sqlBulkCopy.BulkCopyTimeout30 秒的默认值。

回答by eriksv88

Change the CommandTimeoutproperty of your SqlCommand object.

更改SqlCommand 对象的CommandTimeout属性。

The Connect Timeout attribute of a connection string determines how long a SqlConnection Object runs before it stops attempting to connect to a server.

连接字符串的连接超时属性确定 SqlConnection 对象在停止尝试连接到服务器之前运行的时间。

Also change the SqlBulkCopy.BulkCopyTimeoutProperty.

还要更改SqlBulkCopy.BulkCopyTimeout属性。