Closing all sql connections from Solution Explorer.

27. September 2012 17:21 by admin in .net, vs2010 vs2012
In my development work I get the following message quite a lot : Cannot drop database "XXX" because it is currently in use. This usually means I have an existing website or tool with a connection to the database I want to drop. Especially with Entity Framework Code-First I tend to rewrite the whole DB quite often. Instead of killing the 'guilty' process I decided to create a VS shortcut to deal with it. So here's what I have now:

What does this do?

  1. Look for a App.Config or Web.Config of the selected project
  2. Look for connection strings in the configuration file
  3. Use the first connection string and try to connect to the corresponding master db
  4. Close existing connections to the database specified in 3

So HOW does it work?

For this purpose i created a small console application and integrated it into my Visual Studio as an external command. 

The application (source code) is included as a zip file here: (211,17 KB)
This consists of a VS2012 solution but it should be easy to open it in VS2010 as nothing special is done. (For VS2010 just import the .cs files into a 'fresh' project) The heart of the application is the following:

Basically switching between SINGLE_USER and MULTI_USER closes all active connections. 

Next (and final) step is to integrate the program into vs2012. The steps are the same on VS2010 and afaik VS2008. Here's how:
1 Add the program as external tool
Via Tools->External tools click add. Point to the point where you have connection-killer exe file and change the initial directory of the application. Move connection killer up so it is the first external tool (you'll see why later). It should look like this:

2 Create a short in the Solution Explorer context menu
  1. Go Tools->Customize and click the Commands tab. 
  2. Click the context menu 'Project and Solution Context Menus | Project'
  3. Add command select category 'tools' and select command 'External Command 1'
  4. Click 'Modify Selection' and rename the menu item to kill connection or something
  5. Close the dialog and you're done
odzyskiwanie danych 5/28/2015 12:02:19 AM United States #
odzyskiwanie danych

<p>It¡¦s actually a great and helpful piece of info. I¡¦m glad that you shared this helpful info with us. Please stay us informed like this. Thanks for sharing.</p>

Lashay Colapietro - Quick Loans 6/3/2015 8:34:21 PM United States #
Lashay Colapietro - Quick Loans

i can concur with the post

one of a kind bikinis 7/28/2015 9:51:52 PM United States #
one of a kind bikinis

limited edition agua bendita 7/29/2015 6:58:17 PM United States #
limited edition agua bendita

Grisel Taflinger 8/6/2015 11:22:44 AM United States #
Grisel Taflinger

OK, the actual first thing that observing focus on is the writing along with the understanding of SEO. If you know hardly anything about proper SEO strategy it is very good but if your SEO writer has a lot of live through. This way they she aid you far more than far more writing and form content material to fit a plan of action.

Ronnie Blonsky 8/6/2015 11:25:15 AM United States #
Ronnie Blonsky

Now, don't bombard your article with keywords as this can bore your readership. Remember that you are posting articles for its quality content. It should be unique and fresh since this is what readers are searching for. There are also keyword guidelines to be followed to be sure to keep your work is actually still retrieveable. Further, you can create one way links when you submit content to different article folders. There are also article spinning software that can help you make volumes of rewritten blog posts. As you can see, there are many cheap SEO strategies it is possible to use to make sure your marketing strategies are impressive.

Kit Bretado 8/6/2015 11:39:07 AM United States #
Kit Bretado

If a search engine marketing company mentions any black hat practices such as putting hidden text rrn your website, adding your connection to a link farm, or stuffing meta tags with keywords, steer understandable. You can risk getting your website banned out of your search engines by meddling with black hat SEO techniques. The short term results are not worth the end consequences.

Rosendo Zerkle 8/6/2015 11:45:57 AM United States #
Rosendo Zerkle

Garfield Spain 8/6/2015 2:33:44 PM United States #
Garfield Spain

Thomas Drinkwater 8/6/2015 2:36:46 PM United States #
Thomas Drinkwater

A good company always is in touch with its purchasers. In case of any issue or query, company should contact the customer directly while keeping them updated about any incurring products.