Tableadapter.fill times out when table is empty
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
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).
精彩评论