Error 15023: User already exists in current database.
2008-09-09 10:03
363 查看
Error 15023: User already exists in current database.
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]
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]
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]
2) If login account has permission to drop other users, run following T-SQL in Query Analyzer. This will drop the user.
[/code]
Create the same user again in the database without any error.
Stored Procedure 1:
[/code]
Stored Procedure 2:
[/code]
Stored Procedure 3:
[/code]
Reference: Pinal Dave (http://www.SQLAuthority.com)
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.
USE YourDB GO EXEC sp_change_users_login 'Report' GO
[/code]
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 GO EXEC sp_change_users_login 'Auto_Fix', 'ColdFusion', NULL, 'cf' GO
[/code]
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
USE YourDB GO EXEC sp_change_users_login 'update_one', 'ColdFusion', 'ColdFusion' GO
[/code]
2) If login account has permission to drop other users, run following T-SQL in Query Analyzer. This will drop the user.
USE YourDB GO EXEC sp_dropuser 'ColdFusion' GO
[/code]
Create the same user again in the database without any error.
Stored Procedure 1:
/*Following Stored Procedure will fix all the Orphan users in database by mapping them to username already exist for user on server. This SP is required when user has been created at server level but does not show up as user in database.*/ CREATE PROCEDURE dbo.spDBA_FixOrphanUsers AS DECLARE @username VARCHAR(25) DECLARE GetOrphanUsers CURSOR FOR SELECT UserName = name FROM sysusers WHERE issqluser = 1 AND (sid IS NOT NULL AND sid <> 0x0) AND SUSER_SNAME(sid) IS NULL ORDER BY name OPEN GetOrphanUsers FETCH NEXT FROM GetOrphanUsers INTO @username WHILE @@FETCH_STATUS = 0 BEGIN IF @username='dbo' EXEC sp_changedbowner 'sa' ELSE EXEC sp_change_users_login 'update_one', @username, @username FETCH NEXT FROM GetOrphanUsers INTO @username END CLOSE GetOrphanUsers DEALLOCATE GetOrphanUsers GO
[/code]
Stored Procedure 2:
/*Following Stored Procedure will fix all the Orphan users in database by creating the server level user selecting same password as username. Make sure that you change all the password once users are created*/ CREATE PROCEDURE dbo.spDBA_FixOrphanUsersPassWord AS DECLARE @username VARCHAR(25) DECLARE @password VARCHAR(25) DECLARE GetOrphanUsers CURSOR FOR SELECT UserName = name FROM sysusers WHERE issqluser = 1 AND (sid IS NOT NULL AND sid <> 0x0) AND SUSER_SNAME(sid) IS NULL ORDER BY name OPEN GetOrphanUsers FETCH NEXT FROM GetOrphanUsers INTO @username SET @password = @username WHILE @@FETCH_STATUS = 0 BEGIN IF @username='dbo' EXEC sp_changedbowner 'sa' ELSE EXEC sp_change_users_login 'Auto_Fix', @username, NULL, @password FETCH NEXT FROM GetOrphanUsers INTO @username END CLOSE GetOrphanUsers DEALLOCATE GetOrphanUsers GO
[/code]
Stored Procedure 3:
----Following Stored Procedure will drop all the Orphan users in database. ----If you need any of those users, you can create them again. CREATE PROCEDURE dbo.spDBA_DropOrphanUsers AS DECLARE @username VARCHAR(25) DECLARE GetOrphanUsers CURSOR FOR SELECT UserName = name FROM sysusers WHERE issqluser = 1 AND (sid IS NOT NULL AND sid <> 0x0) AND SUSER_SNAME(sid) IS NULL ORDER BY name OPEN GetOrphanUsers FETCH NEXT FROM GetOrphanUsers INTO @username WHILE @@FETCH_STATUS = 0 BEGIN IF @username='dbo' EXEC sp_changedbowner 'sa' ELSE EXEC sp_dropuser @username FETCH NEXT FROM GetOrphanUsers INTO @username END CLOSE GetOrphanUsers DEALLOCATE GetOrphanUsers GO
[/code]
Reference: Pinal Dave (http://www.SQLAuthority.com)
相关文章推荐
- Error 15023: User already exists in current database.
- SQL2000: Error 15023: User or role '%s' already exists in the current database
- user,group,or role 'test' already exists in the current database,error 15023
- 解决SQL Server数据库的"User, group, or role already exists in the current database"问题
- 关于错误信息【schedMgr: Error processing calendar profile document(NoteID: *) in database mail/*.nsf: Cannot find user in Name and Addr
- ubuntu faster-rcnn File already exists in database: caffe.proto
- “A configuration with this name already exists” error in eclipse run configurations
- CI-Based Web Service Error:UserName not defined in database
- Error: "Database 'XXX' is already open and can only have one user at a time"
- Core - Provide an easy way to store administrator and user model differences in a custom store (e.g., in a database)
- Python socket.error: [Errno 98] Address already in use
- com.atomikos.icatch.SysException: Error in init(): Log already in use
- ERROR 1203 (42000): User ivr already has more than 'max_user_connections' active connections
- mysqldump: Got error: 1044: Access denied for user 'sunyard'@'%' to database 'fac_demo' when using L
- net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM.
- ERROR: transport error 202: bind failed: Address already in use
- mfcs100d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRTD.lib(dllmain.obj)
- ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
- Error querying database. Cause:org.h2.jdbc.JdbcSQLException:Table “t_user" not found;SQL statement
- 解决FatalThrowableError in EloquentUserProvider.php line 126: Class '\App\User'问题