Skip to content

March 6, 2014


Entity Framework Code First: Delete a LocalDb instance

by adamstephensen

When working with the Entity Framework Code First I will often get the error below:

An exception of type “System.Data.SqlClient.SqlException’ occurred in EntityFramework.dll but was not handled by in user code’

Additional information: Cannot drop database [database name] because it is currently in use.

To force a delete of the database, follow the steps below.

error_6-03-2014 11-04-30 AM

Figure: This exception is common after you have opened a LocalDb database in Visual Studio.


Open Library Package Manager and Stop the LocalDb instance

a: Select Tools | Library Package manager | Package Manager Console

b: Execute the following two statements

                  sqllocaldb stop v11.0

                  sqllocaldb delete v11.0

error_6-03-2014 11-05-59 AM

Figure: The steps above will stop and delete the LocalDb instance.


Delete the database file from the database


Figure: Open the Solution Explorer and choose Show All Files

error_6-03-2014 11-05-07 AM

Figure: Delete the mdf from the App_Data folder

Read more from Entity Framework
1 Comment Post a comment
  1. Jan 18 2015

    Hello webmaster do you need unlimited content for your page ?
    What if you could copy content from other sites, make it unique and publish on your blog –
    i know the right tool for you, just search in google:
    kisamtai’s article tool


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments