IT/SQLD

[SQL] 현재 데이터베이스에 사용자, 그룹 또는 역활 '계정명'이(가) 이미 있습니다. (오류:15023)

알콩달콩아빠 2023. 4. 18. 14:10
728x90
반응형

* 서버 이전 뒤 디비 복원 후 에러발생

 1. 상황 : 1) MS Server 2003  standard 32bit -> MS Server 2008 standard 64bit R2 로 변경

              2) MS SQL 2008 standard R2 32bit -> MS SQL 2008 standard R2 64bit 로 변경

              3) 6개의 데이터베이스가 있으며 각각의 데이터파일은 스토리지에 네트워크로 연결됨

              4) 원래의 A서버에서 각각의 디비를 '분리'한뒤 B에서 '연결' 작업을 진행하려고함

 

 2.  B디비에서 연결 작업 후 각각의 계정에서 연결한 DB의 사용자 권한을 주려고 하니 15023 에러 발생

     빨리올려야하는데  ㅅㅂ.. 멘붕옴..   

       

 

3. 구글링함.. 아래가 원인이란다.

   master 테이블도 옮겨왔어야하는건가? 라는 의문이 들었으나 일단 이 문제를 해결하여 진행하는걸로 결정.

----------------------------------------------------------------------------------------------------------------------

원인
사용자 로그온 정보는 master 데이터베이스의 syslogins 테이블에 저장됩니다.

서버를 변경하거나, 이전 버전의 master 데이터베이스를 다시 만들거나 다시 로드함으로써 이 정보를 변경할 경우

사용자 데이터베이스 덤프가 만들어졌을 때와 정보가 달라질 수 있습니다. 사용자에 대한 로그온이 존재하지 않는

경우 서버에 로그온하려고 하면 로그인하지 못했다는 오류가 발생합니다. 사용자 로그온이 존재하지만

사용자 데이터베이스의 master에서 syslogins 및 sysusers 테이블에 있는 SUID 값(6.x의 경우)이나

SID 값(7.0의 경우)이 다른 경우 사용자 데이터베이스에서 예상한 것과는 다른 사용 권한이 사용자에게 부여될 수 있습니다.

참고 Microsoft SQL Server 2005를 사용하는 경우 syslogins 테이블 및 sysusers 테이블은 호환성 뷰로 구현됩니다.

이러한 뷰는 sys.syslogins와 sys.sysusers입니다. 호환성 뷰에 대한 자세한 내용은 SQL Server 2005 온라인 설명서의

"호환성 뷰(Transact-SQL)" 항목을 참조하십시오.
----------------------------------------------------------------------------------------------------------------------

 

4. 해결방법

sp_change_users_login(Transact-SQL) 을 사용하면 된다.

sp_change_users_login

Maps an existing database user to a SQL Server login. This feature will be removed in a future version of Microsoft SQL Server.

Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

Use ALTER USER instead.

 

Syntax

sp_change_users_login [ @Action = ] 'action'
    [ , [ @UserNamePattern = ] 'user' ]
    [ , [ @LoginName = ] 'login' ]
    [ , [ @Password = ] 'password' ]
[;]

 

Syntax Argument

[ @Action= ] 'action'
Describes the action to be performed by the procedure. action is varchar(10). action can have one of the following values.

          - Auto_Fix : Links a user entry in the sys.database_principals system catalog view in the current database to a SQL Server login

                            of the same name. If a login with the same name does not exist, one will be created.

                            Examine the result from the Auto_Fix statement to confirm that the correct link is in fact made.

                            Avoid using Auto_Fix in security-sensitive situations.

                            When you use Auto_Fix, you must specify user and password if the login does not already exist,

                            otherwise you must specify user but password will be ignored. login must be NULL.

                            user must be a valid user in the current database. The login cannot have another user mapped to it.

           - Report : Lists the users and corresponding security identifiers (SID) in the current database that are not linked to any login.

                          user, login, and password must be NULL or not specified.

                          To replace the report option with a query using the system tables,

                          compare the entries in sys.server_prinicpals with the entries in sys.database_principals.

          - Update_One : Links the specified user in the current database to an existing SQL Server login.

                                 user and login must be specified. password must be NULL or not specified.

[ @UserNamePattern= ] 'user'
            Is the name of a user in the current database. user is sysname, with a default of NULL.

[ @LoginName= ] 'login' 
            Is the name of a SQL Server login. login is sysname, with a default of NULL.

[ @Password= ] 'password' 
            Is the password assigned to a new SQL Server login that is created by specifying Auto_Fix. If a matching login already exists,

             the user and login are mapped and password is ignored. If a matching login does not exist,

             sp_change_users_login creates a new SQL Server login and assigns password as the password for the new login.

              password is sysname, and must not be NULL.

 

Return Code Values

--------------------------------------------------------------------------------

0 (success) or 1 (failure)

 

5. 해결 진행

   

use  DB_name

EXEC sp_change_users_login 'Report'

GO

 

여기서 결과로 user가 나오면 링크가 안된 user가 있는 것임

auto_fix 옵션을 사용해 보려고 하였으나.. descrition 에 보면 잘 안되는 경우도 있는것 같아서 update_one을 사용하기로함

 

use sse_newweb

go

exec sp_change_users_login 'UPDATE_ONE', 'ssesql', 'ssesql'

go

 

 sp는 앞쪽 value는 UserNamePattern으로 데이터베이스의 사용자를

 뒤쪽 value는LoginName으로 보안카테고리의 사용자를 입력 리턴값은 0 으로 나옴.

 그리고 디비 권한을 다시 주어보면 권한이 잘 주어짐..

 

 

출처 : [SQL] 현재 데이터베이스에 사용자, 그룹 또는 역활 '계정명'이(가) 이미 있습니다. (오류:15023) : 네이버 블로그 (naver.com)

728x90
반응형