tags:

views:

37

answers:

2

I have a VB.NET windows application that when I debug it, it opens the connection. At that point I can see there are two processes created by going to the Activity Monitor in SQL Server Management Studio. I execute my query and then immediately close the connection. However, when I do that the processes do not go away.

For the life of me I can't figure out why not. This hasn't been a problem except that I have a Restore option within the software that doesn't let me restore because the database is in use due to the processes still being open. They do not go away until I exit the application.

+4  A: 

Probably this is just because ADO.Net actually keeps the connection open so you can use it later. This is called connection pooling. Opening and closing connections is an expensive process and connection pooling helps to reduce this cost.

With regards to your restore problem, you can execute SQL to close all open connections on a database. Don't have access to SQLMS at the moment, but if you fill in the delete database dialog with the 'close existing connections' option checked and then output the dialog to SQL you will see it.

James Gaunt
`ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE` boots out all existing connections.
Martin Smith
That's the one! Thanks :)
James Gaunt
A: 
Joel Coehoorn
I think he's talking about spids not sqlserv.exe
Martin Smith
Ah - that makes a lot more sense to me.
Joel Coehoorn