当表为空时 Tableadapter.fill 超时
我有一个视图,我试图用它来填充 TableAdapter。在我的代码中,我第一次正确填充表适配器,过滤我的绑定源并使用 datarowviews 循环数据行并执行所需的更新(由存储过程完成)。现在的问题是,发生这些更新后,我需要再次填充表适配器,以便它反映这些更改。有时我正在使用的视图不会有结果,有时可能会。我无法给出具体的示例,因为数据对工作敏感,但我将尝试创建一个简化的示例,
_taMyView.Fill(_dsMyConnection.MyView)
_bsMyView.Filter = "Number = 1"
For Each drvMyViewRow in _bsMyView
Do Stuff
'stored procedure that updates MyTable (what the view was created from)
Next
_taMyView.Fill(_dsMyConnection.MyView)
_bsMyView.Filter = "Number = 0"
这就是确切的错误“超时已过期。超时期限在操作完成之前已过,或者服务器没有响应。 ”
好的,您会注意到我填充了视图,然后在 Number 等于 1 的列上过滤这些结果。我循环遍历所有这些结果并更新创建视图的表。退出循环后,我点击了第二个 .fill ,大约 20 秒后超时。经过测试,这种超时似乎只发生在 MyView 不保存任何记录的情况下。任何帮助将不胜感激。
一些额外的花絮。我使用 Visual Studio 2010 和 sqlserver 2008。所有工作都是在 VB.NET 中完成的。另外,在调试过程中,我在第二次填充时暂停,转到 Toad for Data Analysts 并运行 SELECT * FROM MyView ,它没有超时,并在大约 19 秒内返回了空结果表。我还尝试在第二次填充之前对表适配器进行处理,但它有类似的超时时间。抱歉,如果这个答案看起来很明显或其他什么,我只是一名实习生,仍在学习这门语言。
编辑
MyAdapter.Adapter.SelectCommand.CommandTimeout = 0
根据我的理解,这似乎已经成功了,让它运行直到完成(如果连接保持打开状态的时间超过了允许的时间)。 ta.fill 的运行速度与 Toad 大约相同,大约在 19-20 秒左右,并且在多次测试后没有出错。感谢您的帮助
I have a View that i am trying to use to fill a TableAdapter with. In my code i fill the table adapter properly the first time, filter my bindingsource and use datarowviews to loop through the rows of data and perform the updates needed (done by a stored procedure). Now the problem is, after these updates take place, i need to fill the tableadapter again so that it reflects these changes. Sometimes the View i am using will have no results, other times it may. I can't give a specific example as the data is work sensitive but i'll try and create a simplified example
_taMyView.Fill(_dsMyConnection.MyView)
_bsMyView.Filter = "Number = 1"
For Each drvMyViewRow in _bsMyView
Do Stuff
'stored procedure that updates MyTable (what the view was created from)
Next
_taMyView.Fill(_dsMyConnection.MyView)
_bsMyView.Filter = "Number = 0"
This is the exact Error "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
Okay, you'll notice that i fill my view, then filter those results on the column Number equal to 1. I loop through all those results and update the table my view is created off of. After exiting the loop i hit the second .fill which times out after about 20 seconds. After testing, this time out only seems to occur when MyView does not hold any records. Any help would be greatly appreciated.
Some extra tidbits. I use Visual Studio 2010 and sqlserver 2008. All work is done in VB.NET. Also, during debugging, i paused on the second fill, went to Toad for Data Analysts and ran a SELECT * FROM MyView which did not time out and returned the empty result table in about 19 seconds. I have also tried doing a dispose on the tableadapter before the second fill but it has a similar time out. Sorry if this answer seems obvious or something, i'm only an Intern and am still learning the language.
EDIT
MyAdapter.Adapter.SelectCommand.CommandTimeout = 0
That seems to have done the trick, from my understanding that lets it run until it finishes (SQLServer will shut it down if the connection stays open longer than it allows). The ta.fill runs at about the same pace as Toad coming in around 19-20 second mark and does not error after multiple tests. Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
19秒?有多少行?视图有多复杂?如果 Toad 或 Management Studio 中的查询需要 19 秒,那么 VB.NET 代码中的查询可能会花费两倍的时间。如果您认为 19 秒太长(我当然这么认为),也许您应该考虑增加 CommandTimeout 值(我认为默认值为 30 秒)和/或优化结构。
19 seconds? How many rows? How complicated is the view? If a query takes 19 seconds from Toad or Management Studio it is quite feasible that it takes double that from your VB.NET code. Perhaps you should think about increasing the CommandTimeout value (default is, I believe, 30 seconds) and/or optimizing the structure if you think 19 seconds is too long (I certainly do).