P
PJHORNSA
Hi all,
I want to create a backup of a database using SQLDMO in C#. But I keep
on getting a exception. If anyone can help me by providing code for
this, it would be appreciated. Thanks in advance...
Code:
+++++++++
try
{
this.Cursor = Cursors.WaitCursor;
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
srv.Connect("server","username","password");
SQLDMO.Backup bak = new SQLDMO.BackupClass();
bak.Devices = bak.Files;
string path = txtPath.Text; //Path where the backup should be
created.
path = "[" + path + "]";
bak.Files = path;
bak.Database = "DatabaseName";
bak.SQLBackup(srv);
MessageBox.Show("Database backed up successfully.", "Backup
Successfull");
this.Cursor = Cursors.Default;
}
catch(Exception err)
{
this.Cursor = Cursors.Default;
MessageBox.Show(err.Message,"Error");
}
Exception
++++++++++
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open backup
device 'C:\test\BackupName.BAK'. Device error or device off-line. See
SQL Server error log for more details.
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP DATABASE is
terminating abnormally.
Paul
I want to create a backup of a database using SQLDMO in C#. But I keep
on getting a exception. If anyone can help me by providing code for
this, it would be appreciated. Thanks in advance...
Code:
+++++++++
try
{
this.Cursor = Cursors.WaitCursor;
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
srv.Connect("server","username","password");
SQLDMO.Backup bak = new SQLDMO.BackupClass();
bak.Devices = bak.Files;
string path = txtPath.Text; //Path where the backup should be
created.
path = "[" + path + "]";
bak.Files = path;
bak.Database = "DatabaseName";
bak.SQLBackup(srv);
MessageBox.Show("Database backed up successfully.", "Backup
Successfull");
this.Cursor = Cursors.Default;
}
catch(Exception err)
{
this.Cursor = Cursors.Default;
MessageBox.Show(err.Message,"Error");
}
Exception
++++++++++
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open backup
device 'C:\test\BackupName.BAK'. Device error or device off-line. See
SQL Server error log for more details.
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP DATABASE is
terminating abnormally.
Paul