question

opnqryf avatar image
opnqryf asked

SQLCMD Script Is Locking Detached Database Files Objects

Running a simple SQLCMD script file, which simply detaches a database on SQL2005, is locking the file system objects so that I cannot copy them to another server or re-attach them. I've looked at the processes running on the server and the cmd.exe object opened, ran, then closed. I cannot restart this 24-7 production e-commerce server or any of the sql server services. Any ideas would be appreciated.

SQLCMD

xp_cmdshell 'sqlcmd -E -SMedusa -i "\\medusa\f$\@detach.sql"'                    

@detach.sql

USE [master]                    
GO                    
ALTER DATABASE [ATLAS] SET SINGLE_USER WITH ROLLBACK IMMEDIATE                    
GO                    
USE [master]                    
GO                    
EXEC master.dbo.sp_detach_db @dbname = N'ATLAS', @keepfulltextindexfile=N'true'                    
GO                    
sql-server-2005databasejoblocking
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Scot Hauder avatar image
Scot Hauder answered

Try adding :QUIT to the end of your batch

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.