x

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                    

more ▼

asked Mar 17, 2010 at 04:02 PM in Default

avatar image

opnqryf
11 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Try adding :QUIT to the end of your batch

more ▼

answered Mar 18, 2010 at 12:31 AM

avatar image

Scot Hauder
6.4k 13 16 22

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2017
x281
x100
x48

asked: Mar 17, 2010 at 04:02 PM

Seen: 2738 times

Last Updated: Mar 17, 2010 at 04:02 PM

Copyright 2016 Redgate Software. Privacy Policy