Skip to main content


Showing posts with the label MSSQL 2008 or MSSQL 2012

How to Fix MSSQL Error 15023: "User already exists in current database" and Stored Procedures for Preventing MSSQL Orphan Users

Whether you are using MSSQL 2005, MSSQL 2008 or MSSQL 2012, orphaned users are common when restoring a database. It happens like this: you restore the database successfully. Being a thorough and awesome database administrator, you check the user mappings for the owner/primary database user assigned to the database, and see that the user exists in your server instance, but is no longer assigned the correct mappings. You attempt to restore the mappings, but when you do, the MSSQL server responds with the error below  Error 15023: "User already exists in current database" Below are a series or commands that can be used to immediately resolve errors like this, followed by a series of stored procedures that can be used in a number of ways to keep your MSSQL instance orphan-free on a more long-term basis. The scripts below assume a number of variables. Keep these in mind and replace them with the correct values before executing the respective queries. The $ character i