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

3

10

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.

Negativism answered 22/10, 2008 at 8:15 Comment(0)
E
5
sqlcmd -t {n}

Where {n} must be a number between 0 and 65535.

Note that your question is a bit misleading since the server has no concept of a timeout and therefore you cannot set the timeout within your script.

In your context the timeout is enforced by sqlcmd

Electrolysis answered 22/10, 2008 at 9:6 Comment(4)
@edg: I've never heard of the -t option of sqlcmd and didn't find it in the documentation. But I checked it sqlcmd -? - and there it is! Bravo!Undue
I guess this won't work. sqlcmd.exe without setting -t explicitly means "no timeout"Moon
Yup. Technically the correct answer to my question, but didn't help the core problem. Thanks anyway!Negativism
You should unaccept it then so others see your question as not-yet-solved.Moon
R
7

Your solution - Add GO every 100 or 150 lines

http://www.red-gate.com/MessageBoard/viewtopic.php?t=8109

Rossie answered 20/3, 2009 at 16:16 Comment(1)
Nice idea, except if your script uses variables.Darsey
E
5
sqlcmd -t {n}

Where {n} must be a number between 0 and 65535.

Note that your question is a bit misleading since the server has no concept of a timeout and therefore you cannot set the timeout within your script.

In your context the timeout is enforced by sqlcmd

Electrolysis answered 22/10, 2008 at 9:6 Comment(4)
@edg: I've never heard of the -t option of sqlcmd and didn't find it in the documentation. But I checked it sqlcmd -? - and there it is! Bravo!Undue
I guess this won't work. sqlcmd.exe without setting -t explicitly means "no timeout"Moon
Yup. Technically the correct answer to my question, but didn't help the core problem. Thanks anyway!Negativism
You should unaccept it then so others see your question as not-yet-solved.Moon
U
4

I think there is no concept of timeout within a SQL script on SQL Server. You have to set the timeout in the calling layer / client.

According to this MSDN article you could try to increase the timeout this way:

exec sp_configure 'remote query timeout', 0 
go 
reconfigure with override 
go 

"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. This value has no effect on queries received by the Database Engine."

P.S.: By 300 MB you mean the resulting file is 300 MB? I don't hope that the script file itself is 300 MB. That would be a world record. ;-)

Undue answered 22/10, 2008 at 9:6 Comment(3)
Yes, the SQL script itself is ~300MB. I doubt it's a world record as it's only 1.4 million rows of a very simple table!Negativism
@Negativism oh, it's used to insert data inside "INSERT" statements... I'm sure there's a reason to do it that way, but couldn't you get the data in a textfile and import it via a DTS-package or somthing similar?Undue
Each line needs to be checked via my API, and while I'm sure I could replicate all the checks via a DTS package, for the time and stress required I might as well just divide the SQL script I already have.Negativism

© 2022 - 2024 — McMap. All rights reserved.