If I run a stored proc using the SqlCommand and the SqlCommand times out does the StoredProc continue to execute or does it get force to quit when the SqlCommand disconnects?
Gets or sets the wait time (in seconds) before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Troubleshoot timeout expired errors If you encounter a connection-timeout error, follow the steps: Increase the connection-timeout parameter. If you use an application to connect to SQL Server, increase the relevant connection-timeout parameter values and check whether the connection eventually succeeds.
CommandTimeout is how long a single command can take to complete. ConnectionTimeout is how long it can take to establish a connection to the server to start with.
It seems that people are confused as to whether this is seconds or milliseconds. The documentation states that the timeout is in seconds. A 1-minute timeout seems reasonable for most queries.
My instinct said that the procedure would still execute so I threw together a simple test.
SQL:
Create Procedure TestDelay
AS
waitfor delay '00:00:40'
update table_1
set dt = getdate()
And in VB.Net (same as C# for this purpose):
Dim con As New SqlConnection(myconnectionstring)
Dim com As New SqlCommand("TestDelay", con)
com.CommandType = CommandType.StoredProcedure
con.Open()
Try
com.ExecuteNonQuery()
Catch ex As Exception
con.Close()
Response.Write(ex.Message)
End Try
The result? The procedure did not complete after the timeout. I checked what was happening during a trace in SQL profiler and sure enough SQL appears to wrap the call in a transaction and must roll that transaction back on the timeout.
Note: This test was run against SQL 2005 but I'd suspect the results to be similar in other versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With