Sometimes, we face several issues while dealing with the SQL Server, the issue we are trying to solve here is discussed below with a step-wise solution. So, we are going to proceed with the error problem and the suitable solution for it. SQL Server sometimes shows the error messages like SQL Database Restore Failed, Database in use. When you try to restore the SQL Server database from backup, there may be a chance to receive an error message that reads as follows:
Restored failed server “server_name”
Why SQL database restored failed, Database in Use error occurs?
What causes the SQL database stuck in restoring issue? It may be that another user is using the database. And when you try to access the database, it shows that it failed to open an error due to the database being used by some other user due to which the restored process is stuck in between and we face the restored fail error. Here, we have covered the minimal possible ways to solve the issue manually or automated way.
So, there could be multiple reasons behind this issue. Some of them are given below:
- When you try to restore the database maybe you are connected to the database.
- You have opened multiple windows while using SQL Server Management Studio(SSMS)
- There might be a chance that some other users may be connected to the master database.
1. I have been using SQL Server for a long time and now when I’m trying to restore the database so it is not able to restore because the database is in use and it is showing an error message like SQL Database Can’t Restore, Database in Use. I never faced this issue before. Can anyone help me to fix this issue?
2. I was restoring the data and it has failed to restore and showing the error message like SQL Database, Failed to Restore, Database in Use. I don’t understand why it is showing database in use error. I also tried some solutions from different websites but doesn’t get an effective solution to fix this error. Can anyone help me to get this error fixed?
How to fix ‘Can’t Restore SQL Database in use’?
When attempting to restore the SQL database make sure there may not be any active database connections. The restore operation will fail if someone uses the database at the same time. So, to fix this issue you can follow any of the given methods:
Method 1- Close all the active Connections in the database.
To close the existing database, follow the given steps:
Step 1. Open SQL Server Management Studio.
Step 2. After connecting to the database, panel will appear on the left side of the SSMS window.
Step 3. In the Object Explorer panel, right-click Databases, and then select Restore Database.
Step 4. In the restore database dialog box select one of the database and in the left panel, click options.
Step 5. On the options page, check the checkbox named, close existing connections to the destination database.
Once all the active connections are closed, proceed with the restore operation.
Method 2- Change the mode from Multiple – User to Single-User Mode.
Changing from multi-user mode by default to a single-user mode will disconnect all the connected users. It is used to disconnect all the connected users without notifying them. To force connected users to go offline follow the given steps:
Step 1. Open the SQL Server, and connect to the database.
Step 2. In the Object Explorer window, select New Query and write the following query into the query window, and click execute:
ALTER DATABASE db_name
SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
Executing the above queries will change the database to single-user mode.
Method 3- Restart the SQL Server again
The users which are using the SQL Database are showing active due to which the error may occur. So , for this you can disconnect the users by restarting the SQL server again by using SQL Server Configuration Manager, SQL Server Management Studio(SSMS), Services console, or the command line.
Steps to restart the Configuration Service from SQL Server Manager are as follows:
Step 1. Browse SQL Server using any of the following paths:
SQL Server 2019 C:\Windows\SysWOW64\SQLServerManager15.msc
SQL Server 2017 C:\Windows\SysWOW64\SQLServerManager14.msc
SQL Server 2016 C:\Windows\SysWOW64\SQLServerManager13.msc
SQL Server 2014 C:\Windows\SysWOW64\SQLServerManager12.msc
SQL Server 2012 C:\Windows\SysWOW64\SQLServerManager11.msc
Step 2. In the left pane of the SQL Server window, Click SQL Server Services. And in the right pane, right-click SQL Server service, then Stop and Start it again.
Step 3. To exit the SQL Server click OK
Method 4 – Solution to Recover SQL Database
If the issue still persists, then there is a problem with your database or the backup file is corrupt. In that situation, you can use the Most Reliable SQL Recovery Tool . This software can fix the SQL Restored failed Database in Use error easily.
You can easily restore data in few simple steps for this you need to first install the software and select the affected MDF or NDF file. Scan the corrupted files so that we can spot the error and fix it. After restoring the database successfully you can also import the database files from the SQL Server to CSV file format.
Step 1. Download and install software and open it. The following screen will appear.
Step 2. Open MDF File
From the software menu Click ‘Open’ and browse the desired MDF file from its location.
Step 3. Select Quick scan for normal corruption of database files and check the auto-detect option if you want to detect the SQL Server version automatically.
NOTE- If the Auto detects option fails then you can also try selecting the SQL server version manually.
Step 4. SQL Server Recovery Software will show the scanning report after performing the Quick Scan operation on MDF Files
Step 5. The software will show the Quick Scan results and recommend an advanced scan if the expected results are not found by Quick Scan.
Click OK to preview.
Step 6. After previewing the database objects like table, views, Triggers, functions, rules, and stored procedure.
Click on Export and start recovering the database.
Here, we have discussed how to deal with SQL Database Restored failed, Database in use. Due to this error issue user is not able to access the database. Also discussed the reasons for the database not being restored and provides several methods to deal with the issue. We explained the manual method with SQL Server Management Studio and the SQL commands to resolve this error. You can use the automated solution if you can’t fix this problem manually.