You get “The login already has an account under a different user name.” when you try to create a user that already exists.
In this case it was a statement somewhere in a database creation script having a statement like this:
exec sp_addlogin N'<<UserName>>', N'<<Password>>', @logonDatabase, @logonLanguage
What happened was that the <<UserName>>
in the script already existed and was used to create the new user using sp_addlogin
.
I know that this is deprecated, but the search above also shows it happen with other ways of adding users.
It had been a while since doing SQL Server, so this was a good time for me to find back the relation between [WayBack] SQL Server Logins and Users
These queries will help you identify which ones are currently in your database:
use CRM124TestJWP go select sl.name as LoginName , su.name as UserName , sl.dbname as DatabaseName from sys.sysusers su join sys.syslogins sl on sl.sid = su.sid select sp.name as LoginName , sp.type_desc as LoginType , dp.name as UserName , dp.type_desc as UserType , sp.default_database_name as DefaultDatabase , dp.default_schema_name as DefaultSchema from sys.server_principals sp join sys.database_principals dp on dp.sid = sp.sid
Via: [WayBack] sql server – The login already has an account under a different user name – Database Administrators Stack Exchange