Interesting SSMS issue with waittype of PREEMPTIVE_OS_LOOKUPACCOUNTSID
Saw a recent issue with SQL2008 sp 1 where SQL Server Management Studio (SSMS) appeared to hang when a DBA expanded the database users tab of a database… ie like this :-
When we looked at the waittype of the SSMS session - via sys.dm_os_waiting_tasks– it was waiting on PREEMPTIVE_OS_LOOKUPACCOUNTSID.
I’d not come across this waittype before, and there was very little information out on the web for it..
Looking at this issue using SQL Profiler – it them became apparent that SSMS was waiting on the function SUSER_SNAME.
I did a quick test using SET STATISTICS TIME to prove it was the SUSER_SNAME function causing our issue :-
SELECT * FROM sys.database_principals -- completes in 6 milliseconds
SELECT SUSER_SNAME(sid),* FROM sys.database_principals -- completes in 188941 milliseconds.
suser_sname validates a sid against Active Directory..
What I haven’t mentioned so far is that the database in question had been restored from a server on a different domain. This domain was untrusted from the current domain. However, it appeared that SSMS was still trying to validate the Windows login of each user when displaying the users list…. and taking a long time to return NULL for each user from the untrusted domain.
When all users that had a login from the untrusted domain are removed from the database – this fixed the issue.
To find out the users that had this issue :-
SELECT name FROM sys.database_principals WHERE type_desc IN(‘WINDOWS_USER’, ‘WINDOWS_GROUP’) and SUSER_SNAME(sid) IS NULL
Although I have not raised this as a case with MS – I do think this is a bug in SSMS – I do not see why windows logins should need to be validated when displaying only user details..