My TableAdapter
is defined in an ADO.NET data set. My stored procedure is executed in 50 seconds in SSMS. When I'm trying to execute it in application I get timeout.
How to set timeout connection value for TableAdapter
?
My TableAdapter
is defined in an ADO.NET data set. My stored procedure is executed in 50 seconds in SSMS. When I'm trying to execute it in application I get timeout.
How to set timeout connection value for TableAdapter
?
There are two places where we can set timeouts.
SqlConnection
SqlCommand
SqlConnection
has ConnectionTimeout
property. It specifies the time ADO.Net waits for when trying to connect to the server. If no connection is made to the Server (network down/server not running etc), an exception is thrown.
SqlCommand
has CommandTimeout
property. It specifies the wait time for the results to come back once the command is executed (you call Execute
/ExecuteNoQuery
etc). If no results are returned in specified time, it throws an exception. By default, the command timeout is 30 seconds. So, if the command is taking 50 seconds, you will get an exception.
For SqlConnection
and SqlCommand
it is simple, simply set the value of the property on the objects.
For the TableAdapter
, you have two ways to set ConnectionTimeout
(both lead to same output). First is to set in the connection string. Second is setting it in the Advanced
properties dialogue when you setup connection for the adapter.
For CommandTimeout
, you need to access the specific command from the adapter which is timing out. If the select command is blowing up, you can use this:
var ta = new YouTableAdapter();
ta.Adapter.SelectCommand.CommandTimeout = 100;
You need to change the time-out on the connection string and not the table adapter:
Connection timeout for SQL server
Good luck.