Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a SQL Server script's timeout from within the script?

Tags:

People also ask

How do you set a timeout in SQL query?

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 you handle timeout exceptions in SQL?

Another one you can put in the sql connection object as well but it will be query specific. SqlConnection myConnection = new SqlConnection(); myConnection. ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30"; myConnection. Open();

What is remote query timeout SQL Server?

You use the remote query timeout option to specify how long (in seconds) a remote operation can take before Microsoft SQL Server times out. The default is 600 , which allows a 10-minute wait. This value applies to an outgoing connection initiated by the Database Engine as a remote query.


I have a large script file (nearly 300MB, and feasibly bigger in the future) that I am trying to run. It has been suggested in the comments of Gulzar's answer to my question about it that I should change the script timeout to 0 (no timeout).

What is the best way to set this timeout from within the script? At the moment I have all of this at the top of the script file in the hopes that one of them does something:

sp_configure 'remote login timeout', 600
go
sp_configure 'remote query timeout', 0
go
sp_configure 'query wait', 0
go
reconfigure with override
go

However, I'm still getting the same result and I can't tell if I'm succeeding in setting the timeout because the response from sqlcmd.exe is the world's least helpful error message:

Sqlcmd: Error: Scripting error.