# Sql-server – How to find out who’s logged on to database

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.

Thanks

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

SELECT @@ServerName AS SERVER
,NAME