SQL Server代理:如何“睡觉”?

时间:2020-12-01 00:27:18

In a scripting step in a scheduled task in SQL Server Agent 2005, I need to trigger a webscript that is running on a different server. I'm doing this:

在SQL Server Agent 2005中的计划任务的脚本编写步骤中,我需要触发在不同服务器上运行的webscript。我这样做:

Dim ie 
Set ie = CreateObject( "InternetExplorer.Application" )

ie.navigate "...to my dreamscript"

' Wait till IE is ready
Do While ie.Busy
    (1)
Loop

ie.Quit
set ie = Nothing

At (1) I would like to "sleep" (e.g. WScript.sleep(..)), but WScript is not available in this environment. Is there another way to "sleep" for a while?

在(1)我想“睡觉”(例如WScript.sleep(..)),但在这种环境下WScript不可用。还有另一种方法可以“睡觉”一段时间吗?

3 个解决方案

#1


1  

You can write a console applicaton and execute the console app in SQL agent job.

您可以编写控制台应用程序并在SQL代理程序作业中执行控制台应用程序。

#2


2  

If you're only trying to have the SQL SErver Agent task that waits for a time period use a T-SQL Task with the script

如果您只是尝试使用等待一段时间的SQL SErver Agent任务,请使用带有脚本的T-SQL任务

WAITFOR DELAY '01:00:00' -- wait for an hour

WAITFOR DELAY '01:00:00' - 等一个小时

and change the time to the duration that you'd like to wait.

并将时间更改为您要等待的持续时间。

HTH Andy

#3


0  

You could execute the wscript by using a SQL Server Agent task with a type of "Operpating System (CmdExec)". This requires that xp_cmdshell be enabled and it is often disabled (by default) due to security concerns. However, it does allow you to initiate programs, such as wscript, that are run at the command prompt.

您可以使用类型为“Operpating System(CmdExec)”的SQL Server代理任务来执行wscript。这需要启用xp_cmdshell,并且由于安全问题,通常会禁用它(默认情况下)。但是,它确实允许您启动在命令提示符下运行的程序,例如wscript。

You could move the code into SQLCLR where you can write a stored procedure in C# or VB.Net. The VB.Net SQLCLR Code would be pretty similar to your original wscript.

您可以将代码移动到SQLCLR,您可以在C#或VB.Net中编写存储过程。 VB.Net SQLCLR代码与原始wscript非常相似。

#1


1  

You can write a console applicaton and execute the console app in SQL agent job.

您可以编写控制台应用程序并在SQL代理程序作业中执行控制台应用程序。

#2


2  

If you're only trying to have the SQL SErver Agent task that waits for a time period use a T-SQL Task with the script

如果您只是尝试使用等待一段时间的SQL SErver Agent任务,请使用带有脚本的T-SQL任务

WAITFOR DELAY '01:00:00' -- wait for an hour

WAITFOR DELAY '01:00:00' - 等一个小时

and change the time to the duration that you'd like to wait.

并将时间更改为您要等待的持续时间。

HTH Andy

#3


0  

You could execute the wscript by using a SQL Server Agent task with a type of "Operpating System (CmdExec)". This requires that xp_cmdshell be enabled and it is often disabled (by default) due to security concerns. However, it does allow you to initiate programs, such as wscript, that are run at the command prompt.

您可以使用类型为“Operpating System(CmdExec)”的SQL Server代理任务来执行wscript。这需要启用xp_cmdshell,并且由于安全问题,通常会禁用它(默认情况下)。但是,它确实允许您启动在命令提示符下运行的程序,例如wscript。

You could move the code into SQLCLR where you can write a stored procedure in C# or VB.Net. The VB.Net SQLCLR Code would be pretty similar to your original wscript.

您可以将代码移动到SQLCLR,您可以在C#或VB.Net中编写存储过程。 VB.Net SQLCLR代码与原始wscript非常相似。