April 20, 2010 at 2:35 pm
Hi,
I have a VbScript file that has oSQLServer.Connect statement using windows authentication. I am trying to pass the servername as parameter from command line.
cscript ScriptJobs.vbs KIRAN\SECONDARY
this value KIRAN\SECONDARY should be passed as the servername in VBScript. I have the following code
Dim ArgObj
Dim ServerName
Set ArgObj=Wscript.Arguments
Set ServerName=ArgObj.Item(0)
Dim oSQLServer
Dim oStream
Set oSQlServer = CreateObject("Wscript.SQLDMO.SQLServer")
Set oStream = CreateObject("ADODB.Stream")
oSQLServer.LoginSecure=True
oSQLServer.Connect "& ServerName"
Dim idStep
Dim ScriptJob
Dim CountJobs
Dim JobName
Dim ScriptAllJobs
For Each oJob In oSQLServer.JobServer.Jobs
CountJobs = oSQLServer.JobServer.Jobs.Count
Next
For idStep = 1 To CountJobs
JobName = oSQLServer.JobServer.Jobs.Item(idStep).Name
ScriptJob = oSQLServer.JobServer.Jobs.Item (idStep).Script(4, "C:\" & JobName & ".sql")
ScriptAllJobs = ScriptAllJobs & ScriptJob
Next
oStream.Open
oStream.WriteText (ScriptAllJobs)
oStream.SaveToFile ("C:\SQLAllScripts.sql"), 2
oStream.Close
oSQLServer.DisConnect
Set oStream = Nothing
Set oSQLServer = Nothing
Set ArgObj=Nothing
However, the parameter that i pass in command line is not being taken as input into the ServerName.
Please help me out with this
April 21, 2010 at 2:06 am
Set ServerName=ArgObj.Item(0)
should be changed to
ServerName=ArgObj.Item(0)
because in VBScript Set is used to assign objects only, not primitive types.
Hope this helps
Gianluca
-- Gianluca Sartori
April 21, 2010 at 2:33 pm
Thanks a lot for replying. Take CAre
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy