Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connection String to SQL Server

Status
Not open for further replies.

bbitzer

Programmer
Feb 4, 2003
8
0
0
US
I have this VBA Code to run and script SQL Server jobs on my local machine. How can I modify it to connect to a network SQL Server from my workstation and script the jobs on the network SQL server? I do have Administrative permissions. I know I need a connection string, but I dont have much expierence and need to start learning. You help is greatly appreciated

Public Sub SQLScriptJobs()

Dim oSS
Set oSS = CreateObject("SQLDMO.SQLServer")

Dim lcstring As String
Dim lcServer As String
Dim oJob As Object
Set oJob = CreateObject("SQLDMO.Job")

Dim lcFile As String

lcServer = "LocalServer"

oSS.LoginSecure = True
oSS.Connect lcServer

lcFile = &quot;<My Computer here >\My Documents\DB_JobScripts\ScriptJobs&quot; & &quot;_&quot; & Year(Now) & Right(&quot;0&quot; & Month(Now), 2) & Right(&quot;0&quot; & Day(Now), 2) & &quot;.sql&quot;

For Each oJob In oSS.JobServer.Jobs

lcstring = lcstring & &quot;-- ***** &quot; & oJob.Name & &quot; ****** &quot; & vbCrLf & vbCrLf

lcstring = lcstring & oJob.Script
Next

Dim fso, txtfile
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set txtfile = fso.CreateTextFile(lcFile, True)
txtfile.Write (lcstring)
txtfile.Close

Set oSS = Nothing
Set fso = Nothing

End Sub
 
see thread705-513233 for how to build the string.

You will need to create a connection object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top