Monday, March 26, 2012

Scheduling DB Scripting

Is there any way I can schedule DB scripting? Let's say I want to script
every production DB on a daily bases.
Thank you in advance for your help
Leon ShargorodskyCreate a job with an ActiveX type and use DMO to script the db's. Here is a
sample:
-- **** SCRIPT ALL USER DB's **** --
Sub Main()
Dim oSS
Set oSS = CreateObject("SQLDMO.SQLServer2")
Dim oDb
Set oDb = CreateObject("SQLDMO.Database2")
Dim lcPwd
Dim lcServer
Dim lcFile
Dim lcDB
lcServer = "BULLDOG2"
oSS.LoginSecure = True
oSS.Connect lcServer
Dim lcDBList
Dim dbArray
lcDBList = "Presents|Northwind|Model"
dbArray = Split(lcDBList, "|")
For Each lcDB In dbArray
Set oDb = oSS.Databases(lcDB)
Dim oT
Set oT = CreateObject("SQLDMO.Transfer2")
lcFile = "C:\Data\DB_Scripts\" & lcDB & "_" & Year(Now) & Right("0"
& Month(Now), 2) & Right("0" & Day(Now), 2) & ".sql"
oT.CopyAllObjects = True
oT.IncludeUsers = True
oT.IncludeLogins = True
oT.IncludeDB = True
oDb.ScriptTransfer oT, 2, lcFile
Set oT = Nothing
Next
Set oDb = Nothing
Set oSS = Nothing
End Sub
Andrew J. Kelly SQL MVP
"Leon Shargorodsky" <LeonShargorodsky@.discussions.microsoft.com> wrote in
message news:C0204E43-0613-4D6B-AE28-53F6DCA3B405@.microsoft.com...
> Is there any way I can schedule DB scripting? Let's say I want to script
> every production DB on a daily bases.
> Thank you in advance for your help
> Leon Shargorodsky|||or you could use a free scripting tool which has a com interface and create
vb script to run it, then create a sql job with an active x step in it and
schedule it to a time you want -
http://www.innovartis.co.uk/databas...evaluation.aspx
It comes free with an evaluation copy of DB Ghost
"Leon Shargorodsky" wrote:

> Is there any way I can schedule DB scripting? Let's say I want to script
> every production DB on a daily bases.
> Thank you in advance for your help
> Leon Shargorodsky|||Andrew, Mark, thanks a lot for your help!
"mark baekdal" wrote:
[vbcol=seagreen]
> or you could use a free scripting tool which has a com interface and creat
e
> vb script to run it, then create a sql job with an active x step in it and
> schedule it to a time you want -
> http://www.innovartis.co.uk/databas...evaluation.aspx
> It comes free with an evaluation copy of DB Ghost
> "Leon Shargorodsky" wrote:
>

No comments:

Post a Comment