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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

backup/restore from sql by scripting

Status
Not open for further replies.

alonak

Programmer
Mar 4, 2003
8
IL
how can i connect to sql server by vbs code
and how can i backup or restore from a code
should i use this sql scripts:
BACKUP DATABASE [NORTWIND] TO DISK = N'C:\MSSQL7\BACKUP\NORTHWIND1' WITH NOINIT , NOUNLOAD , NAME = N'NORTHWIND1 backup', SKIP , STATS = 10, NOFORMAT



RESTORE DATABASE [nortwind] FROM DISK = N'C:\MSSQL7\BACKUP\nortHwind1' WITH REPLACE
 
You can use isql.exe tool to run any kind of SQL statement. To use it in VBS, use the "Wscript.run" method here is an example that worked for me :
Code:
function Gbo_CreatePrinter(st_LNIMPR, st_NPIMPR, st_NOMBAC)
dim st_SQL, st_Cmd, retVal

	Gbo_CreatePrinter = true
	st_SQL = ""
	st_SQL = st_SQL & "INSERT INTO FNAIMPR ("
	st_SQL = st_SQL & "LNIMPR, "
	st_SQL = st_SQL & "NPIMPR, "
	st_SQL = st_SQL & "NUMBAC, "
	st_SQL = st_SQL & "NOMBAC, "
	st_SQL = st_SQL & "TYPIMP "
	st_SQL = st_SQL & ") VALUES ("
	st_SQL = st_SQL & chr(39) & st_LNIMPR & chr(39) & ", "
	st_SQL = st_SQL & chr(39) & st_NPIMPR & chr(39) & ", "
	st_SQL = st_SQL & chr(39) & " " & chr(39) & ", "
	st_SQL = st_SQL & chr(39) & st_NOMBAC & chr(39) & ", "
	st_SQL = st_SQL & chr(39) & "O" & chr(39)
	st_SQL = st_SQL & ");"
	
	st_Cmd = "isql -S" & Gst_ServeurSQL & " -E -U -P -dTPAG -Q" & chr(34) & st_SQL & chr(34)
	
	retVal = Gob_WshShell.run(st_Cmd ,0,true)
	if retVal <> 0 Then
		msgbox &quot;SQL Error in statement[&quot; & st_SQL & &quot;]&quot;
		Gbo_CreatePrinter = false
	end if

End function
Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top