The error details are as follows:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Create failed for User 'testuser'. (Microsoft. SqlServer. Smo)
------------------------------
Additional information:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft. SqlServer. ConnectionInfo)
------------------------------
User, group, or role 'testuser' already exists in the current database. (Microsoft SQL Server, Error: 15023)
Solution
Create a user account without authorization, and then associate the account with the corresponding database user using the following SQL statement.
This avoids re-authorization.
-Shrink SQL code
USE {target database}
EXEC sp_change_users_login 'update _ one', '{username already exists in the target database}', '{username created }'
Another solution
Create a user and authorize the user. Before creating a user account (or authorization), delete the user account with the same name in the corresponding database.
The owner of the restored database is an isolated user.
Query analyzer execution:
Exec sp_change_users_login 'report'
Find isolated users
Exec sp_changedbowner 'sa'
The database owner (dbo) is a non-isolated user.
EXEC sp_MSforeachtable 'exec sp_changeobjectowner ''? '', ''Dbo '''
Change the owner of other tables to the database owner (dbo)
Other isolated users can be deleted or processed by themselves.
Delete an isolated user:
1. Open the Enterprise Manager, expand the server, right-click the local server, and choose Properties:
2. Select the server settings tab and select allow direct modification to the system directory.
3. Open the database system table sysusers, right click -- open table -- return all rows
4. Select the user to be added for restoration, find the relevant row, and right-click to delete
5. You can directly modify and restore the system directory.