Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1042243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:28:40+00:00 2026-05-16T15:28:40+00:00

I am trying to restore a database in my sql server 2005 express edition.

  • 0

I am trying to restore a database in my sql server 2005 express edition. I know that to restore the database I need to make it to single user. I am giving this command to make it to single user

USE [master]
ALTER DATABASE database_name SET SINGLE_USER WITH ROLLBACK IMMEDIATE

This command executed properly and I can even see a small image in the object explorer on this database showing that this is now single user.

Now I am trying to restore the database, by following these steps
->right click on the database and tasks and then to restore database. I am selecting the path where the backup file is located and clicking on restore.

But I still get that error “Exclusive access could not be obtained because database is in use(microsoft.sqlserver.smo). Am I missing anything. I have googled it and all most all the sites suggest that database needs to be in single user mode and nothing else.

I did not try the detach and attaching of database method. I have never done that before and would like to know if that is safe to do.

edit: thanks for the answers. Both suggested me same answer so I am marking one answer as chosen.

I even selected overwrite the existing database from options.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:28:41+00:00Added an answer on May 16, 2026 at 3:28 pm

    First, it’s best to back up and restore rather than detach and attach.

    Second, it’s most likely that the session you’re using to set the database to SINGLE_USER is the one that still has it when you try to run the restore (since you’re using the GUI, it’s connecting under its own session so it’s unable to get access).

    Either do the restore as a text command or switch the query window to use another database first, such as master. Or you could just close the query window so it’s no longer connected.

    You can always check who’s connected with select * from master.dbo.sysprocesses.

    Update

    Assuming the database you want to restore already exists, and if you have a single backup file on disk (that doesn’t have multiple backups in it) and there’s no need to restore log files after restoring the full backup, then restoring via script is super, super easy:

    RESTORE DATABASE DBName FROM DISK = 'C:\path\DBNameBackup.bak';
    

    Learning this syntax will make your life easier because then when you set SINGLE_USER you’re already in the sole session that is connected. Plus, I find that typing the restore command is faster than using the GUI, and I like the control I have over things. Repetition of this eventually cements it in your mind and you don’t have to look up the syntax any more.

    It’s not even that difficult to restore log files. Just one simple thing to remember, WITH NORECOVERY:

    RESTORE DATABASE DBName FROM DISK = 'C:\path\DBNameBackup.bak' WITH NORECOVERY;
    RESTORE LOG DBName FROM DISK = 'C:\path\DBNameBackup1.log' WITH NORECOVERY;
    RESTORE LOG DBName FROM DISK = 'C:\path\DBNameBackup2.log' WITH NORECOVERY;
    RESTORE LOG DBName FROM DISK = 'C:\path\DBNameBackup3.log' WITH NORECOVERY;
    ... 4 5 6 7 and so on
    RESTORE LOG DBName FROM DISK = 'C:\path\DBNameBackupX.log' WITH RECOVERY;
    

    There… you’ve restored your log files, very easily. You can even restore to an exact point in time using WITH STOPAT! Also, if you forget and accidentally submit the last log restore statement WITH NORECOVERY then you just issue RESTORE DATABASE DBName WITH RECOVERY; to perform the final steps to make the database usable (rolling back uncommitted transactions, etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running sql server 2005 I have database A. I am trying to restore from
The database is MS SQL Server Express 2005. The database is in simple mode.
I'm trying to restore a PostgreSQL database by executing the SQL that pg_dump created,
I'm trying to restore a database (SQL SERVER 2008) from a backup in a
I am trying to migrate sharepoint wss 3.0 databases from SQL Express 2005 to
I need to backup (using C#) a SQL 2005 Database to a *.bak file.
I am trying to restore a backup file to SQL Server 2008. I am
In SQL Server Management Studio, if I attempt to restore a database from a
I'm trying to dump a database from another server (this works fine), then restore
I have SQL Server 2005 set up and I backed up a database a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.