ERROR:
An exception occurred while executing a Transact-SQL statement or batch (Microsoft SQL Server, Error: 15023)
The complate Error is
Microsoft SQL Server Management Studio ------------------------------ Create failed for User 'apuser'. (Microsoft.SqlServer.Smo) For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=15.0.18206.0+((SSMS_Rel).191029-2112)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+User&LinkId=20476 ------------------------------ ADDITIONAL INFORMATION: An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) ------------------------------ User, group, or role 'apuser' already exists in the current database. (Microsoft SQL Server, Error: 15023)
Many times the situation occurred as the SQL SERVER USER neither can be created nor modified throwing the above error. Even the user deleted and created again giving the same error again and again . To rectify this..
sp_change_users_login 'AUTO_FIX', 'someuser' -- here the user is 'apuser' so the command is
sp_change_users_login 'AUTO_FIX', 'apuser'
The output of the command should be
The output may different depending on issues, if the issues not there then it will be shown as 0 each.. the command will solve most of the issues , After executing the above test the user creation or modification once again.. if problem still persisting
First of all run following T-SQL Query in Query Analyzer. This will return all the existing users in database in result pan.
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.
After proceeding the above steps check once again
If the problem persisting delete the user and create again by using the following command
USE YourDB
GOEXEC sp_dropuser 'apuser'GO
Delete the user by selecting the assigned database only
An exception occurred while executing a Transact-SQL statement or batch (Microsoft SQL Server, Error: 15023)
The complate Error is
Microsoft SQL Server Management Studio ------------------------------ Create failed for User 'apuser'. (Microsoft.SqlServer.Smo) For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=15.0.18206.0+((SSMS_Rel).191029-2112)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+User&LinkId=20476 ------------------------------ ADDITIONAL INFORMATION: An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) ------------------------------ User, group, or role 'apuser' already exists in the current database. (Microsoft SQL Server, Error: 15023)
Many times the situation occurred as the SQL SERVER USER neither can be created nor modified throwing the above error. Even the user deleted and created again giving the same error again and again . To rectify this..
sp_change_users_login 'AUTO_FIX', 'someuser' -- here the user is 'apuser' so the command is
sp_change_users_login 'AUTO_FIX', 'apuser'
The output of the command should be
The row for user ‘apuser’ will be fixed by updating its login link to a login already in existence.
The number of orphaned users fixed by updating users was 1.
The number of orphaned users fixed by adding new logins and then updating users was 0.
First of all run following T-SQL Query in Query Analyzer. This will return all the existing users in database in result pan.
USE YourDB
GOEXEC 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.
USE YourDB
GOEXEC sp_change_users_login 'Auto_Fix', 'apuser', NULL, 'cf'GO
After proceeding the above steps check once again
If the problem persisting delete the user and create again by using the following command
USE YourDB
GOEXEC sp_dropuser 'apuser'GO
Delete the user by selecting the assigned database only