The database is in single-user mode, and a user is currently connected to it.

I had this issue when I tried to swap the databases after bacpac restore.

“Could not rename the database ‘DbName’. The database is in single-user mode, and a user is currently connected to it”

Given below the steps I followed to address this error

SELECT request_session_id FROM sys.dm_tran_locks 
WHERE resource_database_id = DB_ID('DbNameWithQuotes')

On executing this statement, the output will be given with ‘request_session_id’. Copy the value and use it in the next statement. No quotes needed in the next command

kill spid_value

Execute the last command to enable the database in multi-user mode

use master;
GO 
ALTER DATABASE YourDbName SET MULTI_USER
GO

Go to the database node in SSMS and click refresh. You can see there will be no errors.

About AnithaEswaran

Hello all, Thanks for visiting my blog. I strongly believe in "Knowledge increases by sharing ,not by saving". With that in mind, I started this blog to share my learning with D365FO community. Since I am from technical background, most of my posts would be from X++, Azure integration and other topics. Thanks to my mentor and my colleague Romain Gasnier who guided and helped me in learning many new concepts in Ax. This instilled confidence in me to handle and troubleshoot complex issues.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.