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

opnqryf gravatar 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

Scot Hauder gravatar image

Scot Hauder
6k 13 15 18

(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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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:

x1948
x241
x86
x39

asked: Mar 17, 2010 at 04:02 PM

Seen: 2402 times

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