Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

passing parameters to a vbs file in command line Expand / Collapse
Author
Message
Posted Tuesday, April 20, 2010 2:35 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 12:15 PM
Points: 10, Visits: 354
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
Post #907254
Posted Wednesday, April 21, 2010 2:06 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 2:49 PM
Points: 4,324, Visits: 10,583
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

Get your two-cent-answer quickly
spaghettidba.com
@spaghettidba
Post #907517
Posted Wednesday, April 21, 2010 2:33 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 12:15 PM
Points: 10, Visits: 354
Thanks a lot for replying. Take CAre
Post #908111
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse