Page 1 of 1

Backup via script?

Posted: Tue 26 Oct 2010 07:34
by kurtbilde
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

Posted: Thu 28 Oct 2010 07:32
by AndreyZ
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.

Posted: Tue 24 May 2011 07:35
by kurtbilde
Hello Andrey,

Do you have an example of this?!?

-Kurt

Posted: Tue 24 May 2011 13:10
by AndreyZ
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.

Posted: Mon 30 May 2011 07:21
by kurtbilde
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