views:

688

answers:

3

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:

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  A: 

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

Ken Yao
Thanks, this is not really the answer to the question, but a good solution. I will call the script by using:wscript myscript.vbs /T:90 (this will timeout the script @ 90 seconds)
A: 

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.

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.

+1  A: 

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

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

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

HTH Andy

Hello Andy,that's a possibility to sleep, but it won't work for my purposes - I need to "sleep" while the IE is loading (see above)