SQL Backing up with SMO & C# ?
-
I'm using the following code to back up a SQL Database :
void BackupDatabase(string sConnect, string dbName, string backUpPath)
{
using (SqlConnection cnn = new SqlConnection(sConnect))
{
cnn.Open();
dbName = cnn.Database.ToString();ServerConnection sc = new ServerConnection(cnn); Server sv = new Server(sc); // Create backup device item for the backup BackupDeviceItem bdi = new BackupDeviceItem(backUpPath, DeviceType.File); // Create the backup informaton Microsoft.SqlServer.Management.Smo.Backup bk = new Backup(); bk.PercentComplete += new PercentCompleteEventHandler(percentComplete); bk.Devices.Add(bdi); bk.Action = BackupActionType.Database; bk.PercentCompleteNotification = 1; bk.BackupSetDescription = dbName; bk.BackupSetName = dbName; bk.Database = dbName; //bk.ExpirationDate = DateTime.Now.AddDays(30); bk.LogTruncation = BackupTruncateLogType.Truncate; bk.FormatMedia = false; bk.Initialize = true; bk.Checksum = true; bk.ContinueAfterError = true; bk.Incremental = false; // Run the backup bk.SqlBackup(sv); }
}
In my system (Win7 x64) it works fine but in destination system (WinXP SP3 x86) I receive the below error : Exception[^] How can I fix it ? Thanks. BTW: I installed
SQL Express 2008 R2
in destination system. -
I'm using the following code to back up a SQL Database :
void BackupDatabase(string sConnect, string dbName, string backUpPath)
{
using (SqlConnection cnn = new SqlConnection(sConnect))
{
cnn.Open();
dbName = cnn.Database.ToString();ServerConnection sc = new ServerConnection(cnn); Server sv = new Server(sc); // Create backup device item for the backup BackupDeviceItem bdi = new BackupDeviceItem(backUpPath, DeviceType.File); // Create the backup informaton Microsoft.SqlServer.Management.Smo.Backup bk = new Backup(); bk.PercentComplete += new PercentCompleteEventHandler(percentComplete); bk.Devices.Add(bdi); bk.Action = BackupActionType.Database; bk.PercentCompleteNotification = 1; bk.BackupSetDescription = dbName; bk.BackupSetName = dbName; bk.Database = dbName; //bk.ExpirationDate = DateTime.Now.AddDays(30); bk.LogTruncation = BackupTruncateLogType.Truncate; bk.FormatMedia = false; bk.Initialize = true; bk.Checksum = true; bk.ContinueAfterError = true; bk.Incremental = false; // Run the backup bk.SqlBackup(sv); }
}
In my system (Win7 x64) it works fine but in destination system (WinXP SP3 x86) I receive the below error : Exception[^] How can I fix it ? Thanks. BTW: I installed
SQL Express 2008 R2
in destination system.Is the version of .NET on the XP system the same as that on your Win7 system? If not, you may want to try to build against a lower version if possible. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
I'm using the following code to back up a SQL Database :
void BackupDatabase(string sConnect, string dbName, string backUpPath)
{
using (SqlConnection cnn = new SqlConnection(sConnect))
{
cnn.Open();
dbName = cnn.Database.ToString();ServerConnection sc = new ServerConnection(cnn); Server sv = new Server(sc); // Create backup device item for the backup BackupDeviceItem bdi = new BackupDeviceItem(backUpPath, DeviceType.File); // Create the backup informaton Microsoft.SqlServer.Management.Smo.Backup bk = new Backup(); bk.PercentComplete += new PercentCompleteEventHandler(percentComplete); bk.Devices.Add(bdi); bk.Action = BackupActionType.Database; bk.PercentCompleteNotification = 1; bk.BackupSetDescription = dbName; bk.BackupSetName = dbName; bk.Database = dbName; //bk.ExpirationDate = DateTime.Now.AddDays(30); bk.LogTruncation = BackupTruncateLogType.Truncate; bk.FormatMedia = false; bk.Initialize = true; bk.Checksum = true; bk.ContinueAfterError = true; bk.Incremental = false; // Run the backup bk.SqlBackup(sv); }
}
In my system (Win7 x64) it works fine but in destination system (WinXP SP3 x86) I receive the below error : Exception[^] How can I fix it ? Thanks. BTW: I installed
SQL Express 2008 R2
in destination system.A simple Google action yields this[^]. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Is the version of .NET on the XP system the same as that on your Win7 system? If not, you may want to try to build against a lower version if possible. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
Ravi Bhavnani wrote:
Is the version of .NET on the XP system the same as that on your Win7 system?
The version that I've created the code based on was 9 but the version of destination system is 10, I created the project with 10 version but I receive below Exception :
Restore failed for Server '\\\\.\\pipe\\3F103E6E-3FD4-47\\tsql\\query'.
:(