事务范围内的表适配器更新不断超时
因此,我有一个类型化数据集,我已从另一个数据库为其创建了记录(超过 500,000 条记录!)。我需要将所有这些记录导入到另一个数据库中,并具有以下代码(减去初始化、添加行等):
try
{
Console.WriteLine("Time to process of adding to table: Start at " + startDate.ToString() + " | End at " + DateTime.Now.ToString());
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew, new TimeSpan(1, 0, 0)))
{
laborTicketTableAdapter.Update(laborTicket);
ts.Complete();
}
Console.WriteLine("Time to process transaction: Start at " + startDate.ToString() + " | End at " + DateTime.Now.ToString());
}
catch (SqlException ex)
{
MessageBox.Show("Something bad happened" + Environment.NewLine + ex.StackTrace);
result = false;
}
catch (Exception ex)
{
MessageBox.Show("Something bad happened" + Environment.NewLine + ex.StackTrace);
result = false;
}
控制台输出以下内容:
Time to process of adding to table: Start at 1/1/2009 2:05:59 PM | End at 5/18/2011 2:06:30 PM
The thread '<No Name>' (0xa5c) has exited with code 0 (0x0).
The thread '<No Name>' (0x2e4) has exited with code 0 (0x0).
The thread '<No Name>' (0xae0) has exited with code 0 (0x0).
A first chance exception of type 'System.Transactions.TransactionAbortedException' occurred in System.Transactions.dll
它抛出一个异常,其中包含“事务超时”的内部异常。交易已过期,因此我将超时设置为一小时,但不到 15 分钟后它仍然超时。这是怎么回事?
最终处理时间为下午 2:19:40,运行时间约为 15 分钟。我怎么会遇到这个异常?我在控制台上看到三个线程,但这是一个空项目中的一张白纸。所有其他连接都对外部数据源关闭,当我进行更新时,剩下的就是表适配器和表对象。
- 编辑 - Machine.config 没有 maxTimeout 属性的任何设置
So I have a typed dataset that I have created records for from another database (Over 500,000 records!). I need to import all of these records into the other database and have the following code (minus initialize, adding rows etc):
try
{
Console.WriteLine("Time to process of adding to table: Start at " + startDate.ToString() + " | End at " + DateTime.Now.ToString());
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew, new TimeSpan(1, 0, 0)))
{
laborTicketTableAdapter.Update(laborTicket);
ts.Complete();
}
Console.WriteLine("Time to process transaction: Start at " + startDate.ToString() + " | End at " + DateTime.Now.ToString());
}
catch (SqlException ex)
{
MessageBox.Show("Something bad happened" + Environment.NewLine + ex.StackTrace);
result = false;
}
catch (Exception ex)
{
MessageBox.Show("Something bad happened" + Environment.NewLine + ex.StackTrace);
result = false;
}
The console outputs the following:
Time to process of adding to table: Start at 1/1/2009 2:05:59 PM | End at 5/18/2011 2:06:30 PM
The thread '<No Name>' (0xa5c) has exited with code 0 (0x0).
The thread '<No Name>' (0x2e4) has exited with code 0 (0x0).
The thread '<No Name>' (0xae0) has exited with code 0 (0x0).
A first chance exception of type 'System.Transactions.TransactionAbortedException' occurred in System.Transactions.dll
It throws an exception, with the inner exception of "Transaction timeout". The transaction has expired so I set the timeout to one hour and it still times out after under 15 minutes. What's going on?
Final time of processing was 2:19:40PM, it took around 15 minutes to run. How come I am getting this exception? And I see three threads on the console but this is a blank slate in an otherwise empty project. All other connections are closed to the external data sources and all that is left when I do the update is that table adapter and table object.
-- EDIT --
Machine.config does not have any settings for the maxTimeout attribute
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
异常的原因可能有多种。也许您的实际 SQL 连接超时了?当你的表需要重新组织时,这可能会发生(只是在这里推测)
作为旁节点,你看过 SqlBulkCopy 吗? ( http://msdn.microsoft.com/en- us/library/system.data.sqlclient.sqlbulkcopy.aspx ) ->>;允许您高效地批量加载包含来自其他源的数据的 SQL Server 表。
根据我的经验,这速度非常快。
There can be all kinds of reasons for the exception. Maybe your actual SQL connection had a timeout? this might happen when your table needs to reorganize (just speculating here)
As a sidenode, have you taken a look at SqlBulkCopy? ( http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx ) ->> Lets you efficiently bulk load a SQL Server table with data from another source.
In my experience this is blazingly fast.