Question: Visual studio creates a new database out of thin air to store my data. This is my DbContext:

```
public class LinkedDataContext : DbContext
{
    public DbSet<LinkedData> LinkedData { get; set; }
}

```

No errors are being thrown, I just end up with another database that is only visible through the SQL Server Object Explorer unlike my initially created database which is the top one in the screenshot.

[![enter image description here](https://i.stack.imgur.com/AyfkC.jpg)](https://i.stack.imgur.com/AyfkC.jpg)

**Edit**

I migrated the whole accounts database generated by the MVC project to the MSSQL 2014 server. I simply added a database there and changed the connection string, then it automaticaly populated the database with the needed tables.

So I created my custom table, exactly as it was in the local database. I removed the local databases, the other connection strings and the Controller. Then I rebuild my project and created the controller again. But VS/MVC/EF or whomever is responsible is still creating a local database for my custom data.

When I create the controller it seems to find my table in MSSQL SERVER 2014, otherwise I would get a safe dialogue to store the sql file locally. So what is really happening here? Like I said, the account functionality worked instantly like a charm. My custom table in MSSQL simply won't get used.

**EDIT**

So I set the `DefaultConnectionFactory` in `Web.config` to my MSSQL SERVER 2014 and now it is generating a new Database inside my MSSQL SERVER. It seems to be the namespace, when I create a controller I need to pass in the namespace for the both the Model class and Context class.

```
Model class: LinkedData (DataVisualization.Models)
Data context class: LinkedDataContext (DataVisualization.Models)

```

The databases that keep getting generated automatically to hold my custom data are called: `DataVisualization.Model.LinkedDataContext`.

Does anyone have any idea what is really going on here?

Answer: 
I believe it is just the connection string in your `Web.config`. When you create a `DbContext` from an existing database outside of your project, Visual Studio prompts

> 
> The connection you selected uses a local data file that is not in the
>  current project. Would you like to copy the file to your project and
>  modify the connection?
> 
> 
> 

If you select Yes, this copies the database file into your project, sets its Build Action to Content, sets a relative reference to it in your connection string and sets it to copy to your output directory on build.

If you modify the `connectionString` in your `Web.config` to point to the correct database you should be set (for future reference, answer No when asked if you want to copy it, unless that is really what you want to do - e.g. for a database file you're distributing with your binaries).

As an example, see the two connections listed below. You would see something like `ProjectContext` if you selected Yes, or something like `ExternalContext` if you selected No.

```
  <connectionStrings>
    <add name="ProjectContext" connectionString="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\Database.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
    <add name="ExternalContext" connectionString="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=C:\Programming\.Net\DataVisualization\Data\DataVisualization\App_Data\Database.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
  </connectionStrings>

```

Note that the actual syntax of the `connectionString` may be different in your app depending on settings used, but the key part is the `|DataDirectory|` reference vs the correct path. The path is what you'd need to modify.
STANDARD BEHAVIOR. As bad as it is. Your db template is copied to the runtime every time you hit the "debug" button, so you always start with a new datababase. Painfull as hell. Not sure how other's solve this - I never use this side of visual studio, I have a sql server installed and create my databases there manually. Makes sure i am always working against a defined copy. Obviously VS has no rights to create databases there ;)

If you bother using google or the site search a little you find tons of similar questions - this is a standard problem people regularly get trapped in because it is totally not what they expect.

(if you ask me, the whole db maintenance side of EF is broken anyway, including the "migrations" that hardly can use SQL Server most basic features).