PDF Creator | PDF Converter | PDF Software | Create PDF Send posts as PDF to


Share/Bookmark

SQL SERVER – FIX : Error 15023: User Already Exists in Current Database

SQL SERVER – FIX : Error 15023: User Already Exists in Current Database

Postby Ernie » Thu Jul 27, 2017 2:44 pm

If you restore a database and then try to login to it, you’re likely to run into this wonderful SQL Error:

    User, group, or role ‘whatever’ already exists in the current database (Microsoft SQL Server, Error: 15023).
1. This is the best Solution.
First of all run following T-SQL Query in Query Analyzer. This will return all the existing users in database in result pan.

    Code: Select all
    USE YourDB
    GO
    EXEC sp_change_users_login 'Report'
    GO
Run following T-SQL Query in Query Analyzer to associate login with the username. ‘Auto_Fix’ attribute will create the user in SQL Server instance if it does not exist. In following example ‘ColdFusion’ is UserName, ‘cf’ is Password. Auto-Fix links a user entry in the sysusers table in the current database to a login of the same name in sysxlogins.

    Code: Select all
    USE YourDB
    GO
    EXEC sp_change_users_login 'Auto_Fix', 'ColdFusion', NULL, 'cf'
    GO
Run following T-SQL Query in Query Analyzer to associate login with the username. ‘Update_One’ links the specified user in the current database to login. login must already exist. user and login must be specified. password must be NULL or not specified

    Code: Select all
    USE YourDB
    GO
    EXEC sp_change_users_login 'update_one', 'ColdFusion', 'ColdFusion'
    GO

2. If login account has permission to drop other users, run following T-SQL in Query Analyzer. This will drop the user.

    Code: Select all
    USE YourDB
    GO
    EXEC sp_dropuser 'ColdFusion'
    GO

Create the same user again in the database without any error.
Ernie
Site Administrator
User avatar
Ernie

i'm still here

Site Admin
Site Admin
 
Posts: 206
Joined: Sat Nov 22, 2008 5:32 pm
Location: New Jersey
Highscores: 20
WordPress Blog: Visit User's Blog

Share/Bookmark

Similar topics


Return to SQL 2012

Who is online

Users browsing this forum: No registered users and 1 guest

cron