3702: Cannot drop database because it is currently in use (사용 중이어서 데이터베이스 삭제 불가)
SQL Server의미
데이터베이스를 삭제하거나 이름을 바꾸려 했지만 활성 연결이 여전히 사용 중이어서 거부되었다. SQL Server는 사용 중인 데이터베이스를 삭제할 수 없다.
원인
다른 세션(애플리케이션 풀, 열린 SSMS 탭, 백그라운드 작업)이 삭제하려는 데이터베이스에 연결되어 있다. 자신의 세션이 해당 데이터베이스를 컨텍스트(USE)로 사용하는 것만으로도 발생할 수 있다. 모니터링/백업 도구의 열린 연결도 흔한 원인이다.
해결 방법
삭제 전에 다른 데이터베이스로 전환한다(USE master;). 연결된 세션을 찾아 닫거나, 먼저 데이터베이스를 single-user 모드로 전환한다: ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; 이후 DROP DATABASE [db];를 실행한다. 애플리케이션 커넥션 풀을 중지하고 모니터링 도구가 연결을 열지 않는지 확인한다.
같은 데이터베이스의 다른 항목
- 8645A time out occurred while waiting for memory resources to execute the query (쿼리 실행을 위한 메모리 리소스를 기다리는 중 타임아웃 발생)
- 8651Could not perform the operation because the requested memory grant was not available (요청한 memory grant를 사용할 수 없어 작업을 수행할 수 없음)
- 5061ALTER DATABASE failed because a lock could not be placed on database (데이터베이스에 락을 걸 수 없어 ALTER DATABASE 실패)
- 15138The database principal owns a schema in the database, and cannot be dropped (database principal이 스키마를 소유하고 있어 삭제 불가)
- 1934INSERT/UPDATE failed because the following SET options have incorrect settings (다음 SET 옵션의 설정이 잘못되어 INSERT/UPDATE 실패)
- 468Cannot resolve the collation conflict
- 4864Bulk load data conversion error (type mismatch or invalid character) (대량 로드 데이터 변환 오류)