views:

302

answers:

4

I have written a small application, that can restore a database (C# and SQL2005), but after I have accessed the database, I can't drop it - it says that it is in use.. I guess it has to do with the SQLconnection-pooling, but can I force it to relase the database??

+1  A: 

Specify 'Pooling=False' in the connection string.

leppie
A: 

If you utlise

Using SQLConnection
    '' do your stuff here
End Using

I think this then forces the freeing of resources after it exits

Dean
A: 

Call "USE SomeOtherDB" (e.g Master) to close your own connection, or one of

ALTER DATABASE SET SINGLE_USER

or

ALTER DATABASE SET SINGLE_USER WITH ROLLBACK_IMMEDIATE

to close other connections. The first waits for connections to conclude, the second is immediate.

Stuart Dunkeld
A: 

Dispose your SqlConnection object.

Fabian Vilers