I have a 2008 sql database that is offline that I would like to take online and set to multi-user. Using sql server management studio - new query window - when i execute the following:
ALTER DATABASE mydb SET ONLINE;
ALTER DATABASE mydb SET MULTI_USER;
I receive this error message:
Msg 5064, Level 16, State 1, Line 1 Changes to the state or options of database 'mydb' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.
Msg 5069, Level 16, State 1, Line 1 ALTER DATABASE statement failed. Msg 5064, Level 16, State 1, Line 3 Changes to the state or options of database 'mydb' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it. Msg 5069, Level 16, State 1, Line 3 ALTER DATABASE statement failed.
How would I get the database online and in multi-user mode?
Scroll down to get 'STATE' field. Select Restrict access option from STATE field. Select MULTI_USER from dropdown menu. Click 'OK'.
Use SQL Server Management StudioRight-click the database to change, and then select Properties. In the Database Properties dialog box, select the Options page. From the Restrict Access option, select Single. If other users are connected to the database, an Open Connections message will appear.
A multiuser environment is one in which other users can connect and make changes to the same database that you are working with. As a result, several users might be working with the same database objects at the same time.
a user is currently connected to it
^ This is the problem you need to solve.
Make sure you are not IN that database. Close any query windows that are connected to it, shut down Object Explorer Details, close SSMS and re-open it without Object Explorer connected to that server, etc. Run this:
USE [master];
GO
ALTER DATABASE mydb SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
USE mydb;
GO
That should allow you to bring it online, then you would run the commands you listed.
However:
sys.dm_tran_locks
- it may be that you need to suspend connecting applications and/or shut down SQL Server Agent.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With