Discussion:
Files for SQL Backup
(too old to reply)
PK
2008-03-20 15:44:03 UTC
Permalink
Dear all

Can anybody advise the files and drivers required to run an SQL restore
without having Management Studio Express installed.

This restore will be part of a daily scripted procedure, and i want to keep
system overheads to a minimum as SQLExpress will be running on PCs.

Kr
Paul
Andrea Montanari
2008-03-21 18:30:38 UTC
Permalink
hi,
Post by PK
Dear all
Can anybody advise the files and drivers required to run an SQL
restore without having Management Studio Express installed.
This restore will be part of a daily scripted procedure, and i want
to keep system overheads to a minimum as SQLExpress will be running
on PCs.
at least, I'd say MDAC, which includes SQL Server provider.. so you can even
write a vbs script file to perform it similar to

main:
dim theErr
dim Dest
dim backupSourcefiles
Dim sMoveFiles
theErr = ""
backupSourcefiles = "d:\Share\backufile.Bak"
dest = "c:\folder\"
sMoveFiles = "[" + "db_dataFileName" + "],[" + Dest + "db_data_file.Mdf" +
"],[" + "db_logFileName" + "],[" + Dest +"db_log_file.Ldf" + "]"
Call MountDB ("dbName" , backupSourcefiles, sMoveFiles , theErr)

Function MountDB (Db , SourceFile1, sMoveFiles , theErr)
Const SQLDMORestore_Database = 0

MsgBox "Mount " + Db
DIM oSvr
SET oSvr = CreateObject("SQLDMO.SqlServer")

oSvr.AutoReConnect = True
oSvr.ApplicationName = "Restore my db"
oSvr.LoginTimeout = 15

Fase = "Connect"
On Error Resume Next
oSvr.Connect "(Local)", "userid", "pwd"
theErr = Err.Description
On Error Goto 0

if theErr="" then
Dim oRest
SET oRest = CreateObject("SQLDMO.Restore")
oRest.Database = DB
oRest.Files = "[" & SourceFile1 & "]"
oRest.LastRestore = True
oRest.FileNumber = 1
oRest.ReplaceDatabase = True
oRest.RelocateFiles = sMoveFiles
oRest.Action = SQLDMORestore_Database

MsgBox "Restore " + DB
On Error Resume Next
oRest.SQLRestore oSvr
theErr = Err.Description
On Error Goto 0

if theErr="" then
Dim oDb
On Error Resume Next
Set oDb = oSvr.Databases(DB)
theErr = Err.Description
On Error Goto 0

if theErr="" then
Dim sCommand
sCommand = "Alter Database [" + DB + "] SET MULTI_USER"
MsgBox sCommand
On Error Resume Next
oDb.ExecuteWithResults sCommand, Len(sCommand)
theErr = Err.Description
On Error Goto 0

if theErr="" then
sCommand = "USE [" + DB +"] EXEC sp_changedbowner @loginame = 'sa',
@map = 'true'"
MsgBox sCommand
On Error Resume Next
oDb.ExecuteWithResults sCommand, Len(sCommand)
theErr = Err.Description
On Error Goto 0
end if
end if

set oDB = nothing
end if

End if
MsgBox "Restore errors: " + theErr

SET oSvr = Nothing

End Function

regards
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz http://italy.mvps.org
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
--------- remove DMO to reply
Loading...