sp_adduser depends on being able to access the (deprecated) catalog views in master DB in order to work. Some restrictions to access catalog views are new in SQL Server 2005, and old (deprecated) code does not work when there are restrictions on them.
Most likely the login exists, but the principal executing sp_adduser doesnĄ¯t have permission to access the metadata for the login. I would recommend trying the following code to verify the existence of the login:
CREATE USER [COMMERCIAL DIRECT]
go
The CREATE USER DDL doesnĄ¯t rely directly on the catalog views, and given that suser_sid returns a non-null value, it should work. If the statement above works, then most likely the principal you are using to create the users doesnĄ¯t have permission to access the catalog view.
You can also verify if the login exists using a privileged (i.e. sysadmin) account.
SELECT * FROM sys.server_principals
WHERE sid = suser_sid( N'COMMERCIAL DIRECT' )
I hope this information helps.
-Raul Garcia
SDE/T
SQL Server Engine
Does suser_sid() return the same value when the login exists as when it doesn't Have you attempted to do a reverse lookup on the returned SID value, to see what Windows knows about it (using LookupAccountSid, see for example the code in http://blogs.msdn.com/lcris/archive/2005/09/26/474202.aspx)
Thanks
Laurentiu
I have also had this issue pop up two times, on different customer machines.
I have not yet been able to reproduce this in my environment. The issue has been when we've
backed up a database and restored it onto a different SQL Server machine. Our code tests:
IF SUSER_SID(@ls_login_name) IS NULL
to determine whether or not it should create a new login. Then is tries to synchronize the user.
SUSER_SID(@ls_login_name) returns a non-null value, but the login name does not exist
in syslogins or sys.server_principals. I try sp_droplogin or DROP LOGIN and they both fail
because the login name does not exist. I think both instances happened with SQL 2005 SP2,
but I'm not sure.
I plan on changing my code that synchronizes Users to use ALTER USER ... WITH LOGIN = xxx
to simplify everything, but it is still dependant upon IF SUSER_SID(@ls_login_name) IS NULL.
Is there a better way to see if the Login exists
Thanks for any comments.