How to test if SQL Server database is in Single User Mode
You can check the sys.databases
view ...
if (SELECT user_access_desc FROM sys.databases WHERE name = 'YourDb')
= 'SINGLE_USER'
begin
print 'It is in single user mode!'
end