Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

When I execute this SQL:

USE ASPState
GO
IF NOT EXISTS(SELECT * FROM sys.sysusers WHERE NAME = 'R2Server\AAOUser')
CREATE USER [R2Server\AAOUser] FOR LOGIN [R2Server\AAOUser];
GO

I get the following error:

The login already has an account under a different user name.

How do I know what this different user name is for my login account?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

This means that the login [R2Server\AAOUser] is already mapped to a user in that database. Or, in other words, another database user is using this login. You can see what database user is using your login with the following query:

use YourDB
go
SELECT su.name as DatabaseUser
FROM sys.sysusers su
join sys.syslogins sl on sl.sid = su.sid
where sl.name = 'test' -- login

PS: a version of the script that doesn't use the compatibility views:

Select sp.name as LoginName, sp.type_desc as LoginType,
    dp.name as DBUser, dp.type_desc as UserType
from sys.server_principals sp
join sys.database_principals dp on dp.sid = sp.sid
where sp.name = 'test' -- your login
share|improve this answer
    
Ok, I see the value dbo being displayed. Strange, I don't remember that I have use the dbo for my account R2Server\AAOUser. Wondering what I should do next. –  Jack Feb 22 '13 at 9:06
    
Have you created the database using that login to connect to the server? If yes, then you're the db owner of it and don't need to create another user. You're already set. –  Marian Feb 22 '13 at 9:16
    
Actually, I used the command aspnet_regsql -E -S .\MSSQLSERVER_R2 -ssadd to create the ASPState database. I think probably, I am already set, even though, I even don't realize it in the first place. –  Jack Feb 22 '13 at 9:18
    
Guess what: "-E -> Authenticate with current Windows credentials." :-) –  Marian Feb 22 '13 at 9:29
1  
I would use sys.server_principals and sys.database_principals. sysusers and syslogins are only there for backward compatibility. –  Aaron Bertrand Feb 22 '13 at 14:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.