SqlBulkCopy.BulkCopyTimeout 属性

发布于 2024-08-05 17:46:26 字数 398 浏览 3 评论 0原文

我正在使用 VSTS 2008 + C# + .Net 3.5 + ADO.Net 开发控制台应用程序来执行批量插入复制。

我想同时使用批量插入批量和批量插入超时属性。对于 BulkCopyTimeout 属性,我很困惑,想知道它是适用于整个批量还是仅适用于批量的每批?

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

提前致谢, 乔治

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

靑春怀旧 2024-08-12 17:46:26

在网络上搜索和阅读一些博客文章和论坛帖子似乎表明 SqlBulkCopyTimeout 实际上并不适用于整个操作,而是适用于操作中的每个批次。

MSDN 文档对此并不完全清楚,但大多数帖子似乎都表明超时适用于批处理。在大多数情况下,减少批量大小和/或增加 SqlBulkCopyTimeout 似乎是超时问题的解决方案。

请参阅此论坛帖子作为示例

马克

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

山田美奈子 2024-08-12 17:46:26

BulkCopyTimeout:默认为 30 秒

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

BatchSize:默认整个数据源为一批

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

有关更多详细信息,请参阅此链接:SqlBulkCopy 超时

我们收到此异常“超时已过期”。如果应用程序无法在 30 秒内插入数据源。

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.

悲凉≈ 2024-08-12 17:46:26

它适用于一批的整个操作。您必须确保也设置了连接超时。我之前遇到过超时,将其设置在批量副本上,并发现连接超时也很重要。

看起来整个操作的概念很有趣。如果它最终等待的时间超过了任一时间的超时时间,它将失败。换句话说,如果一个批次的读取花费的时间超过超时时间,它将失败,但如果所有读取的总和>超时你没事。如果批量写入时间太长,也会失败。

但似乎是一批一批的,而不是全部。

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.

生来就爱笑 2024-08-12 17:46:26

找到批量复制的理想超时并不容易;如果您选择较小的Timeout,则不应选择较大的batchSize,因为可能会发生超时错误。另一方面,如果您决定选择较小的批量大小,则服务器出现超时错误的可能性较小;然而,你并不安全。

我的建议是将超时设置为无限制,即(sqlBulkCopy.BulkCopyTimeout = 0),并尝试为批量复制选择相当大的批量大小。至少,你不能有超时异常。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文