How to use the script....

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
kurtbilde
Posts: 114
Joined: Wed 16 Mar 2005 16:02
Location: Odense, Denmark

How to use the script....

Post by kurtbilde » Mon 03 Oct 2011 11:15

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

AndreyZ

Post by AndreyZ » Wed 05 Oct 2011 11:13

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".

kurtbilde
Posts: 114
Joined: Wed 16 Mar 2005 16:02
Location: Odense, Denmark

Post by kurtbilde » Thu 06 Oct 2011 11:58

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

AndreyZ

Post by AndreyZ » Fri 07 Oct 2011 15:31

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;

Post Reply