Tuesday, March 20, 2012

Backup DB to LocalMachine

alslamo alikom...

hope u all be in a good health...

ok...my problem that i have a client application that designed to adminstrate the DB server using SMO...

now iam trying to backup the desired DB from the DB server which is another machine connected to the same network...

i specified the file name and the DB name....and every thing runs smothly with no exceptions....but no file generated in the client machine....and no exception were thrown....

wish to have a solution soon plz....thx for ur time...

and here is sample code:

public bool BackupDB(string dbName, string backupFilePath)

{

try

{

// Create a new backup and specify what to back up

Backup backup = new Backup();

backup.Action = BackupActionType.Database;

backup.BackupSetDescription = "Backup " + dbName + " database";

backup.BackupSetName = dbName + " Backup";

backup.Database = dbName;

backup.Checksum = true;

backup.ContinueAfterError = true;

backup.Incremental = false;

backup.ExpirationDate = DateTime.Now.AddYears(1);

backup.LogTruncation = BackupTruncateLogType.Truncate;

backup.MediaDescription = "File Backup";

backup.Initialize = true;

backup.Restart = true;

backup.RetainDays = 7;

// Create a new backup device, in this case a file

BackupDeviceItem backupItem = new BackupDeviceItem(backupFilePath, DeviceType.File);

backup.Devices.Add(backupItem);

backup.SqlBackup(sqlServer);

return true;

}

catch(Exception ex)

{

return false;

}

}

thx again.....

alaslamo alikom...(Peace Upon You All) "IsLamic Greeting"

Hi,

SMO is just used to remote administer SQL Server. Defining backups is always relative to the Server. If you want to store the information from the server on the client you will have to define a UNC path which points to a client share or any share where you can copy the backup file to the client from in your application code.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||thank you very much.... Mr.Jens K. Suessmeyer

No comments:

Post a Comment