server.Databases.Drop(); fails in MSTest

The following exception is thrown:

Error Message: Microsoft.SqlServer.Management.Smo.FailedOperationException: Drop failed for Database '4d982a46-58cb-4ddb-8999-28bd5bb900c7'. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Cannot drop database "4d982a46-58cb-4ddb-8999-28bd5bb900c7" because it is currently in use.

Any idea what caused this?

Is it possible to call a SMO function to finalize any running Transact-SQL statements?

Answers


As a guess, I wonder if your connection pool is counting against you - i.e. you have previously executed some commands on a SqlConnection that is now being kept around for re-use. You could try disabling pooling? (pooling=false in the connection string, IIRC).

Also - have you been careful to close all your commands/connections/readers etc? Ideally via using? As a last resort, you could try using T-SQL to kill all the other spids from your machine - hacky, but it might work.


Use the Server.KillDatabase(string database) method which closes all open connections for you.


Need Your Help

BULK INSERT Operating System Error Code 32

sql-server sql-server-2005 tsql

I am making use of BULK INSERT within a stored procedure and I get this error:

Is there a non-static ClassInitialize alternative in MSTest?

c# visual-studio-2012 mstest selenium-chromedriver

I'm using Visual Studio 2012 test framework (I guess that's MSTest). I have some code that I need to run once and only once before the various testmethods run. ClassInitialize seemed perfect until I

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.