The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

    • RT @sebvandenbrink: Je ziet Abraham wanneer je 50 wordt, wie zie je wanneer je 90 wordt? Asking for a grandmother... 1 hour ago
    • RT @fmanjoo: Just behold all the resources we’ve given police. Look at all that military gear, enough to fight a civil war with citizens. A… 1 hour ago
    • RT @andizeisler: I’m old enough to remember two weeks ago when mobs of white people armed themselves to the teeth and stormed state capital… 1 hour ago
    • RT @Rubenhuisman1: DeLijn: We zetten extra bussen in zodat studenten naar hun examens kunnen en minder gevaar lopen. Meanwhile NS: StUdEnT… 1 hour ago
    • RT @Foone: The clever bit of the heads of a double-sided 3.5" floppy drive: The heads aren't aligned with each other, they're offset by a l… 1 hour ago
  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,920 other followers

“The login already has an account under a different user name.” – MSSQL

Posted by jpluimers on 2018/07/11

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

Related:

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: