简体   繁体   中英

'Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.'

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.

Related Question Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. working on remote windows .net Linq Count() timing out -Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. While fetching records from database SQL Server Exception:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding ExecuteQueryin linq :Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding Execute package in ssis causes Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM