Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

SQL Server - User, group, or role '...' already exists in the current database. (Microsoft SQL Server, Error: 15023)

DB 파일(mdf/ldf)을 직접 복사해 SQL Server에 (Attach로) 등록하면, 해당 DB에 등록된 사용자가 /Security/Users 수준에 함께 나옵니다. 그런데, 재미있는 건 그 사용자로는 로그인이 안 된다는 점입니다. 그래서 (DB가 아닌) SQL Server 수준에서 사용자를 새롭게 등록해야 하는데요, 이것도 나름대로의 문제를 가지고 있습니다.

가령, DB에 이미 "default902"라는 사용자가 등록돼 있다고 가정할 때, SQL Server 수준에서 이 사용자를 새로 생성한 후 "User Mapping"을 대상 DB로 설정하려고 하면 다음과 같은 오류가 발생합니다.

Create failed for User 'default902'.  (Microsoft.SqlServer.Smo)

For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=16.100.41011.9+(SqlManagementObjects-master-APPLOCAL)&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 'default902' already exists in the current database. (Microsoft SQL Server, Error: 15023)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=15.00.2000&EvtSrc=MSSQLServer&EvtID=15023&LinkId=20476

오류 메시지에도 나오듯이 동일한 사용자가 DB에 이미 등록돼 있다는 건데요, 그래서 DB 수준의 /Security/Users에 등록된 사용자를 삭제하려고 하면 이번엔 이런 오류가 발생합니다.

Drop failed for User 'default902'.  (Microsoft.SqlServer.Smo)

For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=16.100.41011.9+(SqlManagementObjects-master-APPLOCAL)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Drop+User&LinkId=20476

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=15.00.2000&EvtSrc=MSSQLServer&EvtID=15138&LinkId=20476

검색해 보면 다음의 글이 나오는데요,

The database principal owns a schema in the database, and cannot be dropped message
; https://dba.stackexchange.com/questions/19456/the-database-principal-owns-a-schema-in-the-database-and-cannot-be-dropped-mess

SSMS로 해당 DB 문맥에서 SQL Query 창을 열고 다음의 쿼리를 실행하면 (실제로는 SYS.database_principals 테이블의 name 필드에 해당하는) "the schema owner" 필드의 값이 "default902"로 설정돼 있는 것을 확인할 수 있습니다.

SELECT S.*, [the schema owner]=dp.name, dp.type_desc
FROM SYS.schemas S
INNER JOIN SYS.database_principals dp ON S.principal_id = dp.principal_id
where S.name='db_owner'

/* 실행 결과
name		schema_id	principal_id	the schema owner	type_desc
db_owner	16384		5		default902	        SQL_USER
*/

이 상태에서 db_owner를 사용자(default902)에서 dbo로 바꿔주면,

alter authorization
on schema::db_owner
to dbo
go

/* 실행 후 "the schema owner" 확인
name		schema_id	principal_id	the schema owner	type_desc
db_owner	16384		5		dbo			SQL_USER
*/

이제 사용자를 삭제할 수 있습니다.

drop user default902
go

이후에는, SQL 서버 수준에 등록된 사용자 계정으로 "User Mapping"을 해당 DB로 설정하는 것이 가능해집니다.




간혹 이런 작업을 할 때마다 매번 궁금했던 것인데, DB에 등록된 사용자가 그대로 로그인까지 할 수 있게 했어야 하는 게 아닌가... 싶은데 왜 이런 식으로 반드시 SQL 서버 수준의 사용자 계정을 새로 등록하게 만드는 것인지 잘 모르겠습니다. 혹시 제가 모르는 뭔가 다른 방법이 있는 것일까요? ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 8/12/2025]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  [2]  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13975정성태7/23/20251691닷넷: 2347. C# 14 - (3) 형식 인자가 없는 제네릭 타입의 nameof 지원파일 다운로드1
13974정성태7/22/20251743닷넷: 2346. C# 14 - (2) Span 타입과 배열 간의 암시적 형변환파일 다운로드1
13973정성태7/21/20251543닷넷: 2345. C# - 배열 및 Span의 공변성파일 다운로드1
13972정성태7/21/20251500닷넷: 2344. C#의 Identity conversion 의미파일 다운로드1
13971정성태7/17/20251560닷넷: 2343. C# 14 - (1) 속성 구문에서 문맥 키워드로 추가되는 field 예약어파일 다운로드1
13970정성태7/17/20251509닷넷: 2342. C# 14 - (취소된 글)
13969정성태7/17/20251573닷넷: 2341. snap으로 설치한 .NET 리눅스 실행 환경
13968정성태7/16/20251428오류 유형: 969. lddtree - TypeError: 'type' object is not subscriptable
13967정성태7/16/20252073오류 유형: 968. snap으로 설치한 "dotnet run" 실행 시 "undefined symbol: _dl_audit_symbind_alt, version GLIBC_PRIVATE" 오류
13966정성태7/15/20252599디버깅 기술: 223. WinDbg - .kframes 명령어
13965정성태7/11/20251840오류 유형: 967. 디버깅 모드로 실행 시 "Could not find file 'C:\Program Files\IIS Express\Oracle.DataAccess.Common.Configuration.Section.xsd'" 예외
13964정성태7/10/20252910닷넷: 2340. C# - Win32 Multimedia Timer 주기파일 다운로드1
13963정성태7/8/20252406VS.NET IDE: 202. Visual Studio 2022 + Copilot 기본 사용법
13962정성태7/7/20252212스크립트: 79. 파이썬 - onnxruntime_genai에서 지원하지 않는 모델 사용
13961정성태7/5/20251914디버깅 기술: 222. WinDbg 분석 사례 - IISreset 시점에 w3wp.exe의 crash 발생
13960정성태7/3/20253266개발 환경 구성: 752. ProcDump - C/C++ 예외 코드 필터를 지정한 덤프 생성 [2]
13959정성태6/25/20252145오류 유형: 966. Ubuntu - ping: connect: Network is unreachable
13958정성태6/21/20252898닷넷: 2339. C# - Phi-4-multimodal 모델의 GPU 가속 방법 (ORT 사용)파일 다운로드1
13957정성태6/20/20253409닷넷: 2338. C# / Foundry Local - Phi-4-multimodal 모델을 사용하는 방법 [1]
13956정성태6/19/20253255개발 환경 구성: 751. Triton Inference Server의 Python Backend 프로세스
13955정성태6/18/20253168오류 유형: 965. Hugging Face 모델 다운로드 시 "requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: ..." 오류
13954정성태6/18/20252526닷넷: 2337. C# - Hugging Face에 공개된 LLM 모델을 Foundry Local에서 사용하는 방법파일 다운로드1
13953정성태6/16/20252462스크립트: 78. 파이썬 - 소스 코드의 파일 경로를 지정한 모듈 로드
13952정성태6/15/20252831닷넷: 2336. C# - IValueTaskSource로 인해 주의가 필요한 ValueTask 호출파일 다운로드1
13951정성태6/15/20252790오류 유형: 964. Outlook - 일정이 "You cannot make changes to contents of this read-only folder." 오류 메시지로 삭제가 안 되는 경우
13950정성태6/12/20253728닷넷: 2335. C# - 간단하게 구현해 보는 IValueTaskSource 예제파일 다운로드1
1  [2]  3  4  5  6  7  8  9  10  11  12  13  14  15  ...