如何在脚本内设置 SQL Server 脚本的超时?

发布于 2024-07-07 11:46:25 字数 558 浏览 9 评论 0 原文

我有一个很大的脚本文件(接近 300MB,将来可能会更大),我正在尝试运行。 在 Gulzar 对我的有关它的问题的回答的评论中建议,我应该将脚本超时更改为 0(无超时)。

在脚本中设置此超时的最佳方法是什么? 目前,我将所有这些都放在脚本文件的顶部,希望其中一个能够执行某些操作:

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

但是,我仍然得到相同的结果,并且我无法判断我是否成功设置了超时因为 sqlcmd.exe 的响应是世界上最没有帮助的错误消息:

Sqlcmd:错误:脚本错误。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十年九夏 2024-07-14 11:46:25

您的解决方案 - 每 100 或 150 行添加 GO

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

Your solution - Add GO every 100 or 150 lines

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

夜光 2024-07-14 11:46:25
sqlcmd -t {n}

其中 {n} 必须是 0 到 65535 之间的数字。

请注意,您的问题有点误导,因为 服务器没有超时的概念,因此您无法在脚本中设置超时。

在您的上下文中,超时由 sqlcmd

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

自由如风 2024-07-14 11:46:25

我认为 SQL Server 上SQL 脚本中没有超时概念。 您必须在调用层/客户端中设置超时。

根据 这篇 MSDN 文章您可以尝试以这种方式增加超时:

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

“使用远程查询超时选项来指定远程操作在 Microsoft SQL Server 超时之前可以花费多长时间(以秒为单位)。默认值为 600,允许 10-分钟等待。此值适用于数据库引擎作为远程查询发起的传出连接。此值对数据库引擎接收的查询没有影响。”

PS:300 MB 是指结果。文件有300MB? 我不希望脚本文件本身有300 MB。 这将是一项世界纪录。 ;-)

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. ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文