I'm trying to rename a database in SSMS and I get this error:

The database could not be exclusively locked to perform the operation

So how can I find out who or what is using this database? I don't want to go and change anything without knowing what is going to be effected.


  • 1
    run sp_who to see what sessions are logged on to databases. – Tony Hinkle Jun 13 at 17:22

The script below shows what database has users connected, what username, and machine name attached.

 ,getdate() AS DATE
FROM sys.databases d
LEFT JOIN sysprocesses sp ON d.database_id = sp.dbid
WHERE database_id NOT BETWEEN 0   AND 4
 AND loginame IS NOT NULL 
 order by hostname

enter image description here

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.