We use cookies on this website. By using this site, you agree that we may store and access cookies on your device Read More Got it!
Database Recovery 4 minute read

[Fixed]: Database cannot be Opened. It is in the Middle of a Restore

Bharat Bhushan
Written By
Bharat Bhushan
Kuljeet Singh
Approved By
Kuljeet Singh
stellar calander
Published on
February 6th, 2023

Summary: After restoration, when trying to access the database, you may encounter the “Database cannot be opened. It is in the middle of a restore” error. In this post, we will show different ways to fix the error. We’ll also mention a SQL database repair software that can help resolve the issue if it has occurred due to corruption in database.

Free Download for Windows

Contents

  • Reasons for the Database cannot be Opened Issue
  • Solutions to Fix the Database cannot be Opened Issue
  • What to do if the above solution does not work?
  • Conclusion

When trying to access the database in SQL Server, you may receive the following error message:

Database xxx cannot be opened. It is in the middle of a restore.

If you check the status of the database in SSMS, it will show as restoring (see the below image).

Image of Database in the middle of restore

Alternatively, you can check the database status by using the following T-SQL command.

USE master
go
SELECT DATABASEPROPERTYEX(‘stellar’, ‘status’) status

Here, ‘stellar’ is the database name.

Image of database status as restoring

You can also use the sys.databases system view to check the database status.

USE master
go
SELECT state_desc from sys.databases
where name=’stellar’

It will display the following result:

Image of database state as restoring

Here, ‘state_desc’ is the description of the database state.

Reasons for the Database cannot be Opened Issue

If the database is in restoring mode, you cannot use the database. This is why it cannot be opened. However, there are also some other reasons that may lead to this issue, such as:

  • The restoration process failed unexpectedly and the database remains in that state.
  • There is not enough disk space on the server where the database is stored.
  • When restoring the database, you set it in No Recovery mode by mistake.

Solutions to Fix the Database cannot be Opened Issue

If the database is in restore mode, it means that someone is restoring the database. You can contact other DBAs and verify who is restoring the database. If this is the case, then you need to wait until the database is restored.

However, sometimes, the restoring process fails. In such a case, you need to fix the problem.

Let’s assume that you already have a database backup.

To set the database in recovery mode, you can try to restore the database.

  • In SSMS, go to the Object Explorer, right-click the database, and select Restore Database.
Image of Restore database selected in the Object Explorer by right-clicking on Database folder
  • In the Restore Database window, select the database that you want to restore and then select the Backup sets to restore.
Image of backup sets to restore in restore database window
  • In Options, select the Recovery State as RESTORE WITH NORECOVERY.
Image of Recovery state set as restore with norecovery in options page

Basically, there are 3 possible states:

  1. RESTORE WITH RECOVERY is the default option. It is the last backup. You do not have to backup more backup sets.
  2. The NORECOVERY option is used to restore from a backup. Set it to restoring mode and wait for other backups to be restored.
  3. STANDBY is another option that keeps the database in read-only mode. It allows you to check the data and verify that you have the correct data during restoration.

Also, you can use the command line to set the database to Restore mode. Use the following code:

USE [master]
BACKUP LOG [stellar] TO DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\Backup\stellar_LogBackup_2023-01-19_18-05-01.bak’ WITH NOFORMAT, NOINIT, NAME = N’stellar_LogBackup_2023-01-19_18-05-01′, NOSKIP, NOREWIND, NOUNLOAD, NORECOVERY , STATS = 5
RESTORE DATABASE [stellar] FROM DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\Backup\stellar.bak’ WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5
RESTORE LOG [stellar] FROM DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\Backup\stellar_LogBackup_2023-01-19_13-00-38.bak’ WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5
RESTORE LOG [stellar] FROM DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\Backup\stellar_LogBackup_2023-01-19_16-58-07.bak’ WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5
GO

  • To fix the problem, restore the database using the RECOVERY option.
Image of recovery state set to restore with recovery

Alternatively, you can use the following command:

USE [master]
BACKUP LOG [stellar] TO DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\Backup\stellar_LogBackup_2023-01-19_18-19-32.bak’ WITH NOFORMAT, NOINIT, NAME = N’stellar_LogBackup_2023-01-19_18-19-32′, NOSKIP, NOREWIND, NOUNLOAD, NORECOVERY , STATS = 5
RESTORE DATABASE [stellar] FROM DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\Backup\stellar.bak’ WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5
RESTORE LOG [stellar] FROM DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\Backup\stellar_LogBackup_2023-01-19_13-00-38.bak’ WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5
RESTORE LOG [stellar] FROM DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\Backup\stellar_LogBackup_2023-01-19_16-58-07.bak’ WITH FILE = 1, NOUNLOAD, STATS = 5
GO

What to do if the above solution does not work?

It may be possible that your database is corrupt. If that is the case, you can use a third-party SQL repair software, such as Stellar Repair for MS SQL to repair the database. To use the software, follow these steps:

Note: Before proceeding, take your database offline.

Image of database taken offline before proceeding to repair

Download and install Stellar Repair for MS SQL. Then, open the software and find the database file.

Image of Find database option in the software

Once you find the file, select it and press the Repair button.

Image of Repair button to start repairing the database

After repairing, you can also export the data to different formats, like Excel, CSV, and HTML.

Conclusion

In this article, we discussed the “database cannot be opened. It is in the middle of a restore” issue. We also discussed why this problem occurs and how to restore the database and change the status.

We also mentioned Stellar Repair for MS SQL – an advanced software used to restore damaged SQL databases. This software is compatible with any SQL Server version.

About The Author

Bharat

Bharat Bhushan is an experienced technical Marketer working at Stellar Data Recovery - expertise in data care. He is skilled in Microsoft Exchange Database, MSSQL Database troubleshooting & data warehousing. He is a Management Post Graduate having a strong grip in Technology & certified in SAP-SD, Oracle 10g & Informatica Powercenter 9.1.

Best Selling Products

Stellar Repair for MS SQL

Stellar Repair for MS SQL

Stellar Repair for MS SQL is an enterpri

Read More
Stellar Toolkit for MS SQL

Stellar Toolkit for MS SQL

3-in-1 software package, recommended by

Read More
Stellar Converter for Database

Stellar Converter for Database

Stellar Converter for Database is an eff

Read More
Stellar Repair for Access

Stellar Repair for Access

Powerful tool, widely trusted by users &

Read More

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

Image Captcha
Refresh Image Captcha

Enter Captcha Here :

Table of Contents    arrow

  1. Reasons for the Database cannot be Opened Issue
  2. Solutions to Fix the Database cannot be Opened Issue
  3. What to do if the above solution does not work?
  4. Conclusion

Categories

Related Posts

related post
Database Recovery

How to Fix SQL Attach Database Error 9004?

Stellar Author Bharat Bhushan February 3, 2023 Read More
related post
Database Recovery

How to Rebuild and Restore Master Database in SQL Server?

Stellar Author Bharat Bhushan February 2, 2023 Read More
related post
Database Recovery

How to Patch SQL Server?

Stellar Author Bharat Bhushan February 1, 2023 Read More

Free Trial for 60 Days

Technology You Can Trust A Brand Present Across The Globe

Stellar Official Website

Stellar Data Recovery Inc.
48 Bridge Street Metuchen,
New Jersey 08840,
United States

ALSO AVAILABLE AT

ALSO AVAILABLE AT

About

  • About us
  • Career
  • ISMS Policy
  • Privacy Policy
  • Terms of Use
  • License Policy
  • Refund Policy
  • End User License Agreement

RESOURCES

  • Blog
  • Articles
  • Product Videos
  • Knowledge Base
  • Case Studies
  • Whitepapers
  • Software Catalog

NEWS & EVENTS

  • News
  • Events

PARTNERS

  • Affiliates
  • Resellers
  • Distributors

Useful Links

  • Contact Us
  • Support
  • Special Offers
  • Student Discounts
  • Awards & Reviews
  • Downloads
  • Store
  • Sitemap

Stellar & Stellar Data Recovery are Registered Trademarks of Stellar Information Technology Pvt. Ltd. © Copyright 2023 Stellar Information Technology Pvt. Ltd. All Trademarks Acknowledged.

Follow Us Facebook Twitter Linkedin Youtube