6

I had to restore a database, but some of the users were still connected, and had left for the day. Previously, I had set the database to single user, now I do not see that option.

So, I made a change at instance level, setting Properties/Connections/Maximum number of concurrent users to 1, disconnecting all other users from the server.

I restarted the SQL Server service, but now I am unable to access the database at all. The database is up and running, but I can't open a query window or right click on Properties to revert the change.

How can I fix this?

10

First thing, never set Max Number of Concurrent Connections on the server properties page to 1. This option can even prevent administrators logging in, but in any case the Dedicated Administrator Connection can still be used.

  1. Restart services using SQL Server Configuration Manager, try to login and if not successful, use the Dedicated Administrator Connection.
  2. Right click on the Instance name, and change the value for Max Number of Concurrent Connections to 0 (which means maximum) and restart services.

Sometimes, after setting Max Number of Concurrent Connections to 1, on login you may face the following error message:

Cannot open user default database. Login failed.
Login failed for user ‘UserName’

To fix this: In the login window, click on the Options button and in the default database item, select a database like tempdb and then press login.

If the database is in Single_User mode

Using T-SQL:

USE [master];
GO
ALTER DATABASE [YourDatabaseNameHere] SET MULTI_USER WITH NO_WAIT;
GO

Using SSMS:

  • Right click on required database --> Properties
  • On the left of Database properties window, click on Options
  • On the righthand side, scroll down and at bottom you will find a status section
  • Change the Restrict Access value to multi_user

If the database is in Single_User mode, and you want to change it to Multi_User, but can't access it as someone else already have the connection, then:

  1. If you have ALTER ANY CONNECTION rights (part of sysadmin and processadmin fixed server roles), run SP_WHO or SP_WHO2, find the process using the target database and execute:

    KILL processid (Ex: KILL 87)
    

    then execute above T-SQL to bring your database back to multi_user.

  2. Or, you can detach and then attach your database and execute the T-SQL above to bring it to multi_user. This is not recommended on production servers.

2

To add to Assim's solution, you want to check your SQLAgent and stop and disable all of the jobs. I've had to go in and do this for DBAs who were killing processes only to have another one spin up right behind it. Don't forget to reenable the jobs!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.