how to restore a sql database programmatically in c#?
-
hi how to restore a sql database programmatically in c#?
-
hi how to restore a sql database programmatically in c#?
Use the
RESTORE
command and connect to the database server with an user that has access to do restores. (e.g. server admin) You can just use the normal SqlConnection and SqlCommands to do that Important Note: The path to the backup you provide are relative to the SqlServer. If it is not the same server as your application you need to copy the files to the server (or a network share?) first where the database server can restore the backup from. -
hi how to restore a sql database programmatically in c#?
Try this: Backing up an SQL Database in C#[^] - it includes code for backup and restore.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
hi how to restore a sql database programmatically in c#?
The following namespaces can be used to access SQL Server 2005 programmatically: Microsoft.SqlServer.management Microsoft.SqlServer.Management.NotificationServices Microsoft.SqlServer.Management.Smo Microsoft.SqlServer.Management.Smo.Agent Microsoft.SqlServer.Management.Smo.Broker Microsoft.SqlServer.Management.Smo.Mail Microsoft.SqlServer.Management.Smo.RegisteredServers Microsoft.SqlServer.Management.Smo.Wmi Microsoft.SqlServer.Management.Trace
Backup bkpDBFull = new Backup();
/* Specify whether you want to back up database or files or log */
bkpDBFull.Action = BackupActionType.Database;
/* Specify the name of the database to back up */
bkpDBFull.Database = myDatabase.Name;
/* You can take backup on several media type (disk or tape), here I am
* using File type and storing backup on the file system */
bkpDBFull.Devices.AddDevice(@"D:\AdventureWorksFull.bak", DeviceType.File);
bkpDBFull.BackupSetName = "Adventureworks database Backup";
bkpDBFull.BackupSetDescription = "Adventureworks database - Full Backup";
/* You can specify the expiration date for your backup data
* after that date backup data would not be relevant */
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);/* You can specify Initialize = false (default) to create a new
* backup set which will be appended as last backup set on the media. You
* can specify Initialize = true to make the backup as first set on the
* medium and to overwrite any other existing backup sets if the all the
* backup sets have expired and specified backup set name matches with
* the name on the medium */
bkpDBFull.Initialize = false;/* Wiring up events for progress monitoring */
bkpDBFull.PercentComplete += CompletionStatusInPercent;
bkpDBFull.Complete += Backup_Completed;/* SqlBackup method starts to take back up
* You can also use SqlBackupAsync method to perform the backup
* operation asynchronously */
bkpDBFull.SqlBackup(myServer);Mouli
-
hi how to restore a sql database programmatically in c#?
The following namespaces can be used to access SQL Server 2005 programmatically: Microsoft.SqlServer.management Microsoft.SqlServer.Management.NotificationServices Microsoft.SqlServer.Management.Smo Microsoft.SqlServer.Management.Smo.Agent Microsoft.SqlServer.Management.Smo.Broker Microsoft.SqlServer.Management.Smo.Mail Microsoft.SqlServer.Management.Smo.RegisteredServers Microsoft.SqlServer.Management.Smo.Wmi Microsoft.SqlServer.Management.Trace
Backup bkpDBFull = new Backup();
/* Specify whether you want to back up database or files or log */
bkpDBFull.Action = BackupActionType.Database;
/* Specify the name of the database to back up */
bkpDBFull.Database = myDatabase.Name;
/* You can take backup on several media type (disk or tape), here I am
* using File type and storing backup on the file system */
bkpDBFull.Devices.AddDevice(@"D:\AdventureWorksFull.bak", DeviceType.File);
bkpDBFull.BackupSetName = "Adventureworks database Backup";
bkpDBFull.BackupSetDescription = "Adventureworks database - Full Backup";
/* You can specify the expiration date for your backup data
* after that date backup data would not be relevant */
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);/* You can specify Initialize = false (default) to create a new
* backup set which will be appended as last backup set on the media. You
* can specify Initialize = true to make the backup as first set on the
* medium and to overwrite any other existing backup sets if the all the
* backup sets have expired and specified backup set name matches with
* the name on the medium */
bkpDBFull.Initialize = false;/* Wiring up events for progress monitoring */
bkpDBFull.PercentComplete += CompletionStatusInPercent;
bkpDBFull.Complete += Backup_Completed;/* SqlBackup method starts to take back up
* You can also use SqlBackupAsync method to perform the backup
* operation asynchronously */
bkpDBFull.SqlBackup(myServer);for more info - http://www.mssqltips.com/sqlservertip/1849/backup-and-restore-sql-server-databases-programmatically-with-smo/[^]
Mouli