RE: VBScript in SQL Server Agent/Jobs not working
From: AnthonyThomas (AnthonyThomas_at_discussions.microsoft.com)
Date: 11/05/04
- Next message: Me: "Having problems with update statement"
- Previous message: Sasha: "What is the best way to run many scripts on a SQL server?"
- In reply to: Kanan: "RE: VBScript in SQL Server Agent/Jobs not working"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 5 Nov 2004 10:14:02 -0800
Basically, Windows Scripting Host has two script calling executibles, WScript
and CScript. The first, a Windows (GUI) based host, the other, a Command
(Line) based host. You just store the exact same procedure in a file with
the .VBS or .JS extension and call it with WScript or CScript.
Yes, this is what the Agent does. It is also how it calls dts packages.
The problem is that is gets all wrapped up in its own process id as either a
thread or a spawned external process. All kinds of weird side effects can
happen.
Just use a T-SQL job to run the xp_cmdshell 'CScript "<script path>\<script
file>"' and forget about all those other little "features" that come bundled
up with SQL Server.
Here's a starter link, but if you look at the frame, there is a ton of
documentation.
http://msdn.microsoft.com/library/en-us/script56/html/wsoriWindowsScriptHost.asp?frame=true
Good luck.
Sincerely,
Anthony Thomas
"Kanan" wrote:
> I am not sure I know how to use cscript. Can you point me some place where I
> can
> read more about it. Did Cscript help run a VBScrpt program inside SQL Server
> Agent?
> thanks
> Kanan
>
> "AnthonyThomas" wrote:
>
> > I have had problems with the ActiveX Agent Jobs and the ActiveX task in dts.
> > Let SQL Server do what it does and leave all the bells and whistles for some
> > other process.
> >
> > I've had better luck in both Agent and DTS by using xp_cmdshell and calling
> > cscript to an actual script file. Also, this allows me a lot more
> > flexibility in debugging.
> >
> > Sincerely,
> >
> >
> > Anthony Thomas
> >
> >
> > "Kanan" wrote:
> >
> > > Hi,
> > > I have VBScript in one of my job (newly created job) in SQL Server Agent.
> > > THe problem seems to be in running a macro in an EXCEL workbook. Just plain
> > > open and
> > > close works smoothly. The code to run the macro in the EXCEL workbook makes
> > > the job forever. The same VBScript runs in command shell. Any ideas why
> > > there is any issue in SQL Server Agent? here is the code
> > >
> > > Dim objXL
> > > dim objFSO
> > > dim objFolder,objSubFolder, objthisFolder
> > > dim objFile,objstream,bookname
> > > const filename = "\\pashare\pamf
> > > apps\Analysis_SOlutions\SOLUTIONS_DEV\kanans.txt"
> > > set objFSO = CreateObject("Scripting.FileSystemObject")
> > >
> > > set objstream = objFSO.OpenTextFile(filename,1,False,0)
> > > Set objXL = CreateObject("Excel.Application")
> > > objXL.Visible = true
> > > do while not objstream.AtEndOfStream
> > > bookname = objstream.readline
> > > if right(bookname,4) = ".xls" then
> > > objXL.WorkBooks.Open(bookname)
> > > objXL.run("monthly_refresh")
> > > objXL.workbooks.close
> > > end if
> > > loop
> > >
> > > objstream.close
> > > objXL.quit
> > > set objXL = nothing
> > > set objFSO = nothing
> > >
> > >
- Next message: Me: "Having problems with update statement"
- Previous message: Sasha: "What is the best way to run many scripts on a SQL server?"
- In reply to: Kanan: "RE: VBScript in SQL Server Agent/Jobs not working"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|