SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to use SQLDMO_SCRIPT_TYPE options in code


how to use SQLDMO_SCRIPT_TYPE options in code

Author
Message
coolchaitu
coolchaitu
SSC-Addicted
SSC-Addicted (482 reputation)SSC-Addicted (482 reputation)SSC-Addicted (482 reputation)SSC-Addicted (482 reputation)SSC-Addicted (482 reputation)SSC-Addicted (482 reputation)SSC-Addicted (482 reputation)SSC-Addicted (482 reputation)

Group: General Forum Members
Points: 482 Visits: 1032
Hi,

I have the following code that scripts out all agent jobs on a server. I want the generated script to include If not exists condition coz i either want to skip or overwrite existing jobs.

Dim ArgObj
Dim x
Dim ServerName
Set ArgObj=Wscript.Arguments
x=ArgObj.Item(0)
ServerName=Mid(x,3)
Wscript.Echo(ServerName)


Dim oSQLServer
Dim oStream
Set oSQlServer = CreateObject("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

JobName = oJob.Name
if (InStr(UCase(JobName), "MIRRORING") > 0) Then
Wscript.Echo("Skipping Job"&JobName)
else
ScriptJob = Replace(oJob.Script(4
,"C:\"& JobName &".sql") , ServerName, "(local)")
ScriptAllJobs = ScriptAllJobs & ScriptJob

End If
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

Where and how do i implement in this code?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search