Search
  • For Individuals
      « Back
    • Windows Data Recovery

      Recovers lost or deleted Office documents, emails, presentations & multimedia files.

      Free Standard Professional Premium

    • Mac Data Recovery

      Recovers deleted files, photos, videos etc. on Mac.

      Free Standard Professional Premium

    • Photo Recovery

      Recover photos, videos, & audio files from all cameras and storage on Windows or Mac.

      Free Standard Professional Premium

    • Video Repair
    • Photo Repair
    • iPhone Data Recovery
  • For Business
      « Back
    • Email Repair & Converter

      Repair for Exchange Converter for EDB Converter for OST Converter for NSF Converter for OST MBOX Repair for Outlook

    • Database & File Repair

      Repair for MS SQL Repair for Access Repair for QuickBooks Software Repair for Excel Extractor for Windows Backup Repair for MySQL

    • Data Recovery & Erasure

      Data Recovery Professional Data Recovery Technician Mac Recovery for Technician Virtual Machine Recovery File Erasure Software Mobile Erasure Drive Erasure File Eraser Software File Eraser Software for Mac

    • Toolkit

      Exchange Toolkit Outlook Toolkit File Repair Toolkit MS SQL Toolkit Data Recovery Toolkit

    • Forensic

      Email Forensic Exchange Auditor Log Analyzer for MySQL Log Analyzer for MS SQL

  • Store
  • Partners
  • Services
  • Offers
  • Support

 

  • For Individuals
    DIY software for anyone who works with data.

    Windows Data Recovery Recovers lost or deleted Office documents, emails, presentations & multimedia files

    Free Standard Professional Premium

    Mac Data Recovery Especially for Mac users to recover deleted documents and multimedia files from macOS

    Free Standard Professional Premium

    Video Repair Windows Mac Repair multiple corrupt videos in one go. Supports MP4, MOV & other formats.

    StandardPremium

    Photo Recovery Windows Mac Recover photos, videos, & audio files from all cameras and storage on Windows or Mac.

    Standard Professional Premium

    iPhone Data Recovery Windows Mac Recover deleted photos, videos, contacts, messages etc. directly from iPhone & iPad

    Recover Erase Toolkit

    Photo Repair Windows Mac Repair multiple corrupt photos in one go. Supports JPEG & other formats.

    Standard Professional Premium


  • For Business
    • Email Repair
    • Email Converter
    • File Repair
    • Data Recovery & Erasure
    • Toolkit
    • Forensic

    Exchange Repair Repair corrupt EDB file & export mailboxes to Live Exchange or Office 365

    Outlook PST Repair Repair corrupt PST & recover all mailbox items including deleted emails & contacts

    OLM Repair Repair Outlook for Mac (OLM) 2011 & 2016 backup files & recover all mailbox items

    Exchange Toolkit Repair EDB & Exchange backup file to restore mailboxes, convert OST to PST, & convert EDB to PST

    Active Directory Repair Repair corrupt Active Directory database (Ntds.dit file) & extract all objects in original form

    EDB to PST Convert online & offline EDB file & extract all mailbox items including Public Folders in PST

    OST to PST Convert inaccessible OST file & extract all mailbox items including deleted emails in PST

    NSF to PST Convert IBM Notes NSF file & export all mailbox items including emails & attachments to PST

    MBOX to PST Convert MBOX file of Thunderbird, Entourage & other clients, & export mailbox data to PST

    OLM to PST Convert Outlook for Mac Data File (OLM) & export all mailbox data to PST in original form

    GroupWise to PST Convert GroupWise mail & export all mailbox items - emails, attachments, etc. - to PST

    EML to PST Convert Windows Live Mail (EML) file & export mailbox data - emails, attachments, etc. - to PST

    Office 365 to PST Connect to Office 365 account & export mailbox data to PST and various other formats

    DBX to PST Convert Outlook Express (DBX) file & export all mailbox data - emails, attachments, etc. - to PST

    SQL Repair Repair corrupt .mdf & .ndf files and recover all database components in original form

    Access Repair Repair corrupt .ACCDB and .MDB files & recover all records & objects in a new database

    QuickBooks Repair Repair corrupt QuickBooks® data file & recover all file components in original form

    MySQL Repair Repair MyISAM & InnoDB tables and recover all objects - keys, views, tables, triggers, etc.

    Excel Repair Repair corrupt Excel (.XLS & .XLSX) files and recover tables, charts, chart sheet, etc.

    BKF Repair Repair corrupt backup (BKF, ZIP, VHDX and .FD) files and restore complete data

    Database Converter Interconvert MS SQL, MySQL, SQLite, and SQL Anywhere database files

    PowerPoint Repair Repair corrupt PPT files and restore tables, header, footer, & charts, etc. like new

    File Repair Toolkit Repair corrupt Excel, PowerPoint, Word & PDF files & restore data to original form

    Data Recovery Windows Mac Recover lost or deleted data from HDD, SSD, external USB drive, RAID & more.

    Technician Toolkit

    Tape Data Recovery Retrives data from all types and capacities of tape drives including LTO 1, LTO 2, LTO 3, & others.

    Virtual Machine Recovery Recover documents, multimedia files, and database files from any virtual machine

    File Erasure Permanently wipe files and folders, and erase traces of apps and Internet activity.

    Standard Corporate

    Mobile Erasure Certified and permanent data erasure software for iPhones, iPads, & Android devices

    Drive Erasure Certified and permanent data erasure software for HDD, SSD, & other storage media Windows Mac

    Exchange Toolkit 5-in-1 software toolkit to recover Exchange database, convert EDB to PST, convert OST to PST, restore Exchange backup, and reset Windows Server password.

    Outlook Toolkit Comprehensive software suite to repair PST files, merge PST files, eliminate duplicate emails, compact PST files, and recover lost or forgotten Outlook passwords.

    File Repair Toolkit Powerful file repair utility to fix corrupt Word, PowerPoint, and Excel documents created in Microsoft Office. It also repairs corrupt PDF files and recovers all objects.

    MS SQL Toolkit 5-in-1 software toolkit to repair corrupt SQL database, restore database from corrupt backup, reset database password, analyze SQL logs, & interconvert databases.

    Data Recovery Toolkit Software helps to recovers deleted data from Windows, Mac and Linux storage devices. Also supports recovery from RAIDs & Virtual Drives.

    Email Forensic Advanced email forensic solution for cyber experts to audit, analyze, or investigate emails & gather evidences.

    Exchange Auditor Exchange Server monitoring solution to automate audits, scans and generate reports ìn real-time.

    Log Analyzer for MySQL Analyze forensic details of MySQL server database log files such as Redo, General Query, and Binary Log.

    Log Analyzer for MS SQL Track & analyze MS SQL Server database transactions log files.

    STELLAR EMAIL FORENSIC

    Advanced email forensic tool to analyze and collect the mailbox data of email clients

    Learn More arrow


    All Products

    All Products

    All Products

    All Products

  • Our Partners
  • Lab Services
  • Trending Searches

    Data Recovery

    Photo Recovery

    Video Repair

    iPhone Data Recovery

    File Erasure Software

    Exchange Repair

    OST to PST

    PST Repair

    Raid Recovery

    MS SQL Repair

  • English Deutsch Français Nederlands Italiano Español 日本語 简体中文
  • Support
Toolkit for MS SQL 6 minute read

[Error Solved] SQL Database Restore Failed, Database in Use

Updated on July 28th, 2021
Priyanka Chauhan
Written By
Priyanka Chauhan
Raja Jegan R
Approved By
Raja Jegan R

Summary: This blog will describe solutions to fix the ‘SQL database restore failed, database in use’ error. These solutions include disconnecting active connections (users and processes) to the database and by using Stellar Toolkit for MS SQL software to recover SQL database (db) from corrupt db or backup (.bak) file. The solutions apply to MS SQL Server 2019, 2017, 2016, 2014 and lower versions.

[Error Solved] SQL Database Restore Failed, Database in Use

When trying to restore SQL Server database from backup, it is common to receive an error message that reads as follows:

Restored failed for Server ‘xxx’ (Microsoft.SqlServer.SmoExtended)

Additional Information: System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use.

SQL Database is in use

Figure 1: SQL Database Restore Failed Error Message

Contents

  • Reasons behind ‘SQL Database Restore Failed, Database in Use’ Error
  • Before We Begin
  • How to Fix ‘can’t restore SQL database because it is in use’ Problem?
  • What if the problem still persists?
  • Conclusion

Reasons behind ‘SQL Database Restore Failed, Database in Use’ Error

Below are some reasons that could interfere with the restore process and throw the ‘restore of database failed because the database is in use’ error:

  • You are connected to the database you are trying to restore.
  • While using SQL Server Management Studio (SSMS) to do a database restore, you have more than one window open in it.
  • Other users are connected to the master db.

Now, we will discuss solutions to fix the error.

Tip: SQL Server database can be restored from the backup (.bak) file. But, the database restore operation may fail if the .bak file is corrupt. Use Stellar Toolkit for MS SQL software that comes with an efficient SQL backup extractor tool designed to help database administrators recover SQL database from corrupted backup (.BAK) file. The software supports SQL Server 2019, 2017, 2016, 2014, 2012, & older versions.

Before We Begin

Before proceeding with resolving the error – exclusive access could not be obtained because the database is in use, make sure to meet the following prerequisites:

  • SQL Server, of any version, must be installed on your system.
  • You will need SQL Server Management Studio (SSMS) installed on your computer.

How to Fix ‘can’t restore SQL database because it is in use’ Problem?

When attempting to restore SQL Server db, make sure there are no active connections. If someone is using the database, the restore operation will fail. To resolve the issue, you will need to disconnect the active users. You can do so, by following any of these methods:

NOTE: Before disconnecting the users, use SQL stored procedure ‘sp_who’ to check all users currently using the db. If you find users performing some important tasks, notify those users before disconnecting them. For detailed information on sp_who, refer to this link. If you don’t want to notify users, skip to method 2.

Method 1 – Close the existing connections to the database

To close existing connections to SQL db, follow these steps:

Step 1: Open SSMS and connect to the db.

Step 2: After connecting to the database, Object Explorer panel will appear on the left side of the SSMS window.

Step 3: In Object Explorer panel, right-click Databases, and then select Restore Database.

Select Restore Database Option
Figure 2: Restore Database

Step 4: In Restore Database dialog box, do the following:

  • Select one of the databases to restore.
  • In the left panel, click Options.

Step 5: In Options page, check the checkbox labeled, ‘close existing connections to destination database’.

Close existing database connections
Figure 3: Close Existing Connections

Once the SQL Server connections are closed, proceed with the restore operation.

Method 2 –Change from multiple-user mode to single-user mode

Changing the multiple-user mode by default to single user mode will disconnect all the connected users. This option can be used, if you want to disconnect all the users without notifying them.

To force users to go offline (i.e. disconnect) from SQL Server, set the db from multiple-user mode to single-user mode by following these steps:

Step 1: Open SSMS, connect to the database.

Step 2: In Object Explorer window, select New Query. Copy and paste the below T-SQL code snippet into the query window, and then click Execute:

USE master;
GO
ALTER DATABASE AdventureWorks2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
Figure 4: SSMS Query Editor

Executing the above code will change the database to single-user mode.

Method 3 – Restart the SQL Server Service

You can also disconnect the users by restarting the SQL service. You can restart the service by using SQL Server Configuration Manager, SSMS, services console, or the command line.

NOTE: Use this method as a last resort. That’s because, you may only need to restore a single db, but restarting the server will kill connections to all databases.

Steps to restart the service from SQL Server Configuration Manager are as follows:

Step 1: Browse SQL Server Configuration Manager using any of the following path:

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 SQL Server Configuration Manager window, click SQL Server Services. And in the right pane, right-click SQL Server service, and Stop and Start it.

Step 3: Click OK to exit the SQL Server Configuration Manager.

Figure 5: SQL Server Configuration Manager Window

What if the problem still persists?

If the issue still persists, likely there is a problem with your database or the backup file, used for restoring the database, is corrupt. In that case, use Stellar Toolkit for MS SQL. The software can recover db from a corrupt SQL Server. It can also extract a database – from corrupt backup (.bak) files – that need to be restored.

Stellar Toolkit for MS SQL software can also help you reset lost or forgotten SQL Server Administrator and user passwords. You can read the software review done by MVP from here.

To restore database from corrupt SQL Server backup (.bak) file by using the software, follow these steps:

Step 1: Download, install and launch Stellar Toolkit for MS SQL software.

Step 2: In software’s user interface, select Extract from MS SQL Backup.

Step 3: In Stellar Backup Extractor for MS SQL window, click Select File to choose the .bak file.

Select corrupt backup file
Figure 6: Select Backup (.bak) File

NOTE: Choose ‘Search in Folder’ option, if you do not know the file location.

Step 4: After selecting the .bak file, click Scan.

Step 5: The BackupSet window appears with details of all the backups.

List of available backups in BackupSet
Figure 7: List of Available Backups

Step 6: Choose the .bak file you want to recover from the Backup Type list, and then click Next to proceed with the scanning process.

Step 7: Once scanning is complete, a dialog box appears displaying the number of total records available in the backup file.

Step 8: The software shows a preview of the database records.

Step 9: To save the recovered .bak file, click Save on File menu.

Step 10: In the window that pops-up, choose MSSQL under Save As, and then click Browse to select the location to save the recovered file. Click OK.

SQL backup file saving formats
Figure 8: Backup File Saving Formats

Step 11: Choose New Database or Live Database under Saving Options. Next, specify details required in Connect to Server section, and then click Connect.

Options for saving sql backup file
Choose backup file saving options
Figure 9: Backup File Saving Options

Step 12: Click OK when the ‘Recovery process successfully completed’ message appears.

Saving complete of SQL backup file
Figure 10 – Recovery Complete Message Box

The recovered file will get saved in the selected location.

You can watch the complete video from here:

Conclusion

This blog explained how to fix the SQL database restore failed, database in use problem. You can disconnect active users by closing the existing connections or by changing from multiple-user mode to single-user mode. Or, disconnect all the users by restarting the SQL Server service. But, if you still have issues restoring the db, Stellar SQL Database Toolkit can come in handy. It helps resolving the issue by repairing the corrupt SQL db or by recovering the SQL Server backup file.

About The Author

Priyanka

Priyanka is a technology expert working for key technology domains that revolve around Data Recovery and related software's. She got expertise on related subjects like SQL Database, Access Database, QuickBooks, and Microsoft Excel. Loves to write on different technology and data recovery subjects on regular basis. Technology freak who always found exploring neo-tech subjects, when not writing, research is something that keeps her going in life.

Best Selling Products

Stellar Data Recovery Professional for Windows

Stellar Data Recovery has the right Windows Recovery tool for all your data recovery

Read More

Stellar Data Recovery Professional for Mac

Stellar Data Recovery for Mac program performs safe..

 

Read More

Stellar Photo Recovery

A comprehensive photo recovery software to restore photos, music & video files

 

Read More

Stellar Repair for Video

Powerful video repair tool for repairing corrupt or damaged MOV and other video files

 

Read More

6 comments

  1. Pritom Nandy says:
    June 11, 2020 at 5:10 am

    In addition to Method# 1 we can check “Replace Existing Database” from the option panel.

    Reply
  2. www.bamzib2.com says:
    April 18, 2020 at 4:33 am

    This post helped me solve the issue.
    I appreciate it, great job!

    Reply
  3. Sunil says:
    September 8, 2019 at 10:36 am

    when I try to backup SQL Server database in PHP following error occurs how to solve it?

    Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 4035 [code] => 4035 [2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Processed 312 pages for database ‘qms’, file ‘qms’ on file 2. [message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Processed 312 pages for database ‘qms’, file ‘qms’ on file 2. ) ) 1

    Reply
  4. Vivek Chandran says:
    September 8, 2019 at 2:36 am

    Great! This is helpful.

    When I used SP_WHO I found a SELECT query on my DB entry in the result. I then realized I need to either close all query windows that point to my DB or change DB selection to master/another to get rid of this error.

    Hope this might be helpful for someone.

    Reply
  5. Rose R. Howard says:
    December 28, 2018 at 9:17 am

    While restoring the database from backup file, I got the following error:
    Restore failed for server.(Microsoft.SqlServer.SmoExtended).
    System.Data.SqlClient.SqlError: The file
    ‘C:\ProgramFiles\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\payroll_file.mdf’
    cannot be overwritten. It is being used by database ‘payroll_file’. (Microsoft.SqlServer.Smo)

    Please provide best solution.

    Reply
    1. Eric Simson says:
      December 28, 2018 at 9:30 am

      To rectify this problem change the file name for .mdf and .ldf which was taken while backup. Follow below steps:
      1. Click on Options Under ‘Select a Page’ section
      2. Choose the Original file name which you want to provide and restore the DB file as
      3. Click on the Browse button and change the file name (payroll_file2.mdf and payroll_file2.ldf)
      4. After changing the database file name (mdf & ldf), now restore the database.

      Reply

Leave a comment Cancel reply

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

  −  1  =  1

Table of Contents    

  1. Reasons behind ‘SQL Database Restore Failed, Database in Use’ Error
  2. Before We Begin
  3. How to Fix ‘can’t restore SQL database because it is in use’ Problem?
  4. What if the problem still persists?
  5. Conclusion

Categories

Related Posts

how to restore specific tables from sql database backup file
Toolkit for MS SQL

How to Restore Specific Table(s) from SQL Database Backup File?

Stellar Author Saba Zehra Rizvi November 16, 2021 Read More
How to Take SQL Server Database Backup Automatically
Toolkit for MS SQL

How to Take SQL Server Database Backup Automatically

Stellar Author Charanjeet Kaur August 12, 2021 Read More
Identify Corrupted SQL Backup File
Toolkit for MS SQL

How to Identify Corrupted SQL Backup File

Stellar Author Charanjeet Kaur February 24, 2021 Read More

Stellar Official Website

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

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
Follow Us

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

DMCA.com Protection Status
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!