Backup via 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

Backup via script?

Post by kurtbilde » Tue 26 Oct 2010 07:34

Hi,

Have anybody with success done a full backup/restore via a script and TMSSQL?

It seems like I can't get the '-sign into the SQL string, so I can't setup the backup filename (via the N'c:\temp\backupname.bak') and it keep on saying that there is an incorrect syntax near GO-stement.

So anyone succeded?

-Kurt

AndreyZ

Post by AndreyZ » Thu 28 Oct 2010 07:32

Hello,

Try using the TMSDump component to export data from a database. TMSDump serves to store a database or its parts as a script and also to restore database from received script.

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

Post by kurtbilde » Tue 24 May 2011 07:35

Hello Andrey,

Do you have an example of this?!?

-Kurt

AndreyZ

Post by AndreyZ » Tue 24 May 2011 13:10

Here is a code example of backing up a database:

Code: Select all

MSConnection.Server := 'server';
MSConnection.Database := 'database';
MSConnection.Username := 'username';
MSConnection.Password := 'password';
MSConnection.LoginPrompt := False;
MSDump.Connection := MSConnection;
MSDump.BackupToFile('filename');
and of restoring a database:

Code: Select all

MSConnection.Server := 'server';
MSConnection.Database := 'database';
MSConnection.Username := 'username';
MSConnection.Password := 'password';
MSConnection.LoginPrompt := False;
MSDump.Connection := MSConnection;
MSDump.RestoreFromFile('filename');
But note that the TMSDump component serves for storing data from tables or editable views as a script, and for restoring data from a received script. It means that TMSDump doesn't create code for creating or dropping tables, it creates code only for their data.
Last edited by AndreyZ on Fri 07 Oct 2011 15:26, edited 1 time in total.

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

Post by kurtbilde » Mon 30 May 2011 07:21

Ok (and thanks)!!!!

SMMS does the backup via script and it makes the hole lot (metadata, data, constraints, indexes ect.) - so I guess I have to look in that direction. Anybody using this approach and have some code?

-Kurt

Post Reply