Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the timeout for a manually executed query in SQL Server?

I have a simple SQL script that I execute manually from Visual Studio. It is a data generation script so I expect it to take a couple of minutes to run. But I get the following error.

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

I don't want to change any global server settings to be able to run this one file. Is there any commands that I could put at the top of the file to increase the timeout for just that script/transaction?

like image 552
tpower Avatar asked Feb 04 '09 10:02

tpower


People also ask

How do I change a timeout query in SQL Server?

Using SQL Server Management StudioIn Object Explorer, right-click a server and select Properties. Click the Connections node. Under Remote server connections, in the Remote query timeout box, type or select a value from 0 through 2,147,483,647 to set the maximum number seconds for SQL Server to wait before timing out.

How do I fix query timeout expired?

You need to configure timeout parameter in SQL server settings as shown on the screenshot. 'Remote query timeout' parameter must be set in 0 instead of 600.

How can correct query execution time in SQL Server?

Using Client StatisticsGo to Menu >> Query >> Select Include client Statistics. Execute your query. In the results panel, you can see a new tab Client Statistics. Go to the Client Statistics tab to see the execution time.


4 Answers

Increasing the CommandTimeout property will solves the problem i.e.

SqlCommandObject.CommandTimeout = 500000

like image 138
Biswa Avatar answered Oct 15 '22 19:10

Biswa


@christian answer did not work for me (changing the settings in SQL Management Studio).

Biswa answer worked for me. I will include code to clarify

SqlCommand cmd = new SqlCommand("MyReport", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 60;  /* note default is 30 sec */
like image 37
Hammad Khan Avatar answered Oct 15 '22 19:10

Hammad Khan


If you use SQL Management Studio, there are two settings in the options (I'm referring to Management Studio from SQL Server 2005, which I use):
(my Management Studio is in German, so I hope I translated the names correctly into English)

You can find both in the menu under "Extras" --> "Options"

In the options, the first one is under "Query Execution", you can set the "Execution Timeout" there (mine was on zero already)

The second one (and I think this is what you need) is the first option under "Designer", it says something like "Override Timeout for table designer updates", you can check a box and put in a value there.
Some time ago, I had a problem similar to yours (timeout message when running ALTER TABLE on a large table), and I solved it by setting this option to a higher value.

like image 33
Christian Specht Avatar answered Oct 15 '22 19:10

Christian Specht


Increase the Query timeout and Connection timeout values in Visual Studio using the procedures documented below. Changing the Query Timeout:

In Visual Studio IDE, navigate to Tools -> Options ->Database Tools ->Query and View Designers You can either uncheck the option Cancel long running query or change the value of Cancel after option to a higher value. Changing the Connection Timeout:

In Visual Studio IDE, enable Server Explorer by navigating to View ->Server Explorer In the Server Explorer, right click on the connection to SQL Server where the CLR objects are being deployed and choose Modify Connection. Click on Advanced button on the Modify Connection window. In the Advanced Properties window change the Connect Timeout value under Initialization section to a higher value.

http://support.microsoft.com/kb/2011805

like image 41
user2197038 Avatar answered Oct 15 '22 19:10

user2197038