Pls any body help. I am in a crucial situation :( I want to back up and restore database which is created in sql server 2000. how can I use this in C#. The code which I have written is not working properly. It throws an exception at step 31. Pls Help
// Create a new connection to the selected server name
ServerConnection srvConn = new ServerConnection(serverName, dBUser, dBPassword);
// Log in using SQL authentication instead of Windows authentication
srvConn.LoginSecure = false;
// Create a new SQL Server object using the connection we created
srvSql = new Server(srvConn);
private void btnBackup_Click(object sender, EventArgs e)
{
if (srvSql != null)
{
saveFileDialog1.Filter = "All Backup Files |*.bkp";
saveFileDialog1.CheckPathExists = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = saveFileDialog1.FileName;
if (!File.Exists(filename))
File.Create(filename);
// Create a new backup operation
Backup bkpDatabase = new Backup();
// Set the backup type to a database backup
bkpDatabase.Action = BackupActionType.Database;
// Set the database that we want to perform a backup on
bkpDatabase.Database = dBase;
// Set the backup device to a file
BackupDeviceItem bkpDevice = new BackupDeviceItem(filename, DeviceType.File);
// Add the backup device to the backup
bkpDatabase.Devices.Add(bkpDevice);
// Perform the backup
bkpDatabase.SqlBackup(srvSql);
}
}