I want to restore database from selected drive but each time it throws the following exception
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
But this is only for a specific database when I tried to restore another one then its worked perfectly.
Can anyone help me out please.
Following code I have used
openFileDialog1.ShowDialog();
query("IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = '" + cmbDatabaseName.Text + "') DROP DATABASE " + cmbDatabaseName.Text + " RESTORE DATABASE " + cmbDatabaseName.Text + " FROM DISK = '" + openFileDialog1.FileName + "'");
lbmsg.Visible = true;
lbmsg.Text = "Database Backup file has been restore successfully";
You problem is DROP DATABASE because there must be some connections to it. Put this command into your code: ALTER DATABASE
query("
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = '" + cmbDatabaseName.Text + "');
ALTER DATABASE " + cmbDatabaseName.Text + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE " + cmbDatabaseName.Text + ";
RESTORE DATABASE " + cmbDatabaseName.Text + " FROM DISK = '" + openFileDialog1.FileName + "';
");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.