Page 1 of 1

How to use the script....

Posted: Mon 03 Oct 2011 11:15
by kurtbilde
I want to use this script:

Code: Select all

BACKUP DATABASE [AdventureWorks] TO  
	DISK = N'\nas\Backup\L40\SQL2005\AdventureWorks_backup_200702120215.bak' 
	WITH NOFORMAT, NOINIT,  NAME = N'AdventureWorks-Full Database Backup', 
	SKIP, NOREWIND, NOUNLOAD,  STATS = 10
And I want to read it backin again:

Code: Select all

RESTORE DATABASE [AdventureWorksNew] 
	FROM  DISK = N'\nas\Backup\L40\SQL2005\AdventureWorks_backup_200702120215.bak' 
	WITH  FILE = 1,  
	MOVE N'AdventureWorks_Data' TO N'C:\Data\MSSQL.1\MSSQL\Data\AdventureWorksNew_Data.mdf',  
	MOVE N'AdventureWorks_Log' TO N'C:\Data\MSSQL.1\MSSQL\Data\AdventureWorksNew_Log.ldf',  
	NOUNLOAD,  STATS = 10
It seems like I get an illegal chars when I try.. (the syntax near thing)..

-Kurt

Posted: Wed 05 Oct 2011 11:13
by AndreyZ
Please specify the exact problem you encountered with backing up and restoring. Can you execute these queries? If no, specify the exact errors that occur. If the problem doesn't concern execution of these queries, please describe in details what you mean by "illegal chars".

Posted: Thu 06 Oct 2011 11:58
by kurtbilde
Hi Andrey,

When using the TMSSql.sql.add(>>script<<); there is the '-issue eg. how does the different paths and titel gets added to the SQL.

Code: Select all

N[b]'[/b]\nas\Backup\L40\SQL2005\AdventureWorks_backup_200702120215.bak[b]'[/b]
and

Code: Select all

N[b]'[/b]AdventureWorks-Full Database Backup[b]'[/b]
I've tried using params as well, but I keep on getting the wrong syntax near-error when TMSSQL.executing;.

-Kurt

Posted: Fri 07 Oct 2011 15:31
by AndreyZ
To avoid problem with quotes, you should double them in your script. Please try using the following code and check if the problem persists:

Code: Select all

MSScript.SQL.Add('BACKUP DATABASE [AdventureWorks] TO');
MSScript.SQL.Add('DISK = N''\nas\Backup\L40\SQL2005\AdventureWorks_backup_200702120215.bak''');
MSScript.SQL.Add('WITH NOFORMAT, NOINIT,  NAME = N''AdventureWorks-Full Database Backup'',');
MSScript.SQL.Add('SKIP, NOREWIND, NOUNLOAD,  STATS = 10');
MSScript.Execute;

MSScript.SQL.Add('RESTORE DATABASE [AdventureWorksNew]');
MSScript.SQL.Add('FROM  DISK = N''\nas\Backup\L40\SQL2005\AdventureWorks_backup_200702120215.bak''');
MSScript.SQL.Add('WITH  FILE = 1,');
MSScript.SQL.Add('MOVE N''AdventureWorks_Data'' TO N''C:\Data\MSSQL.1\MSSQL\Data\AdventureWorksNew_Data.mdf'',');
MSScript.SQL.Add('MOVE N''AdventureWorks_Log'' TO N''C:\Data\MSSQL.1\MSSQL\Data\AdventureWorksNew_Log.ldf'',');
MSScript.SQL.Add('NOUNLOAD,  STATS = 10');
MSScript.Execute;