SMO.Detach fails due to active connection.

December 18th, 2009 - 12:20 pm ET by Morris Neuman | Report spam
I am programming in VS2008 C# using SMO
I would like to execute a SMO.Server.Detach(Database) which works if there
are no connections open and fails if there is an open connection which makes
sense.

My question is:
Is there an SMO method to force all connections closed or force the dtabase
to be in a state so that the server.detach() will not fail?

Thanks
Morris

Thanks
Morris
email Follow the discussionReplies 1 replyReplies Make a reply

Similar topics

Replies

#1 Erland Sommarskog
December 18th, 2009 - 05:23 pm ET | Report spam
Morris Neuman () writes:
My question is:
Is there an SMO method to force all connections closed or force the
dtabase to be in a state so that the server.detach() will not fail?



ALTER DATABASE db SET SINGLE_USER WITH ROLLBACK IMMEDIATE

How you do this with SMO mumbo-jumbo rather than a direct T-SQL command,
I don't have any idea.

Erland Sommarskog, SQL Server MVP,

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sql...14207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sql...95970.aspx
SQL 2000: http://www.microsoft.com/sql/prodin...books.mspx
email Follow the discussion Replies Reply to this message
Help Create a new topicReplies Make a reply
Search Make your own search