title: ASP.NET retrieving data from nowhere
body: <p>I am going through <a href="http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3" rel="nofollow noreferrer">ASP.NET MVC 3 tutorial</a>. Got to the point where <a href="http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-a-model" rel="nofollow noreferrer">EnityFramework was used for model classes</a>. I ran the the application without having connection strings in the web.config specified and it worked.</p>
  <p>I could add, edit, delete records. And the weirdest thing is that they are sill there even after I stop development server and start debugging application again as if table was created somewhere in memory and stayed alive for some reason. Can anybody explain what was going on?</p>
  <p>Here's a link to an image:
  oi48.tinypic.com/fnbeba.jpg</p>
  <p>Was it supposed to use the the connection string for which name matches the name of the class derived from DbContext?</p>
  <p>EDIT1:<br>
  Because I had no connection string in web.config it was generated by Enity Framework using namespace and the name of the class derived from DBContext. By default EF uses SQL Express, hence database file was created in database server's DATA direcotry C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA.</p>
  <p>The last thing I don't understand why it wouldn't create the database file in App_Data dir if DBContext derived class is</p>
  <pre><code>public class MoviesDBContex : DbContext
  {
      public DbSet&lt;Movie&gt; Movies { get; set; }
      
      // Passing name of the connections string shouldn't be even necessary
      public MoviesDBContex()
          : base(&quot;MoviesDBContex&quot;)
      { }
  }
  </code></pre>
  <p>and web.config contains</p>
  <pre><code>  &lt;connectionStrings&gt;
      &lt;add name=&quot;MoviesDBContext&quot;
        connectionString=&quot;Data Source=|DataDirectory|Movies.sdf&quot;
        providerName=&quot;System.Data.SqlClient&quot;/&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  <p>Thist what the Microsoft guide about ER connections and models (msdn.microsoft.com/en-us/data/jj592674.aspx) says:</p>
  <blockquote>
  <p>If the name of the connection string matches the name of your context (either with or without namespace qualification) then it will be found by DbContext when the parameterless constructor is used. If the connection string name is different from the name of your context then you can tell DbContext to use this connection in Code First mode by passing the connection string name to the DbContext constructor.</p>
  </blockquote>
  <p>Any idea why database file isn't created in App_Data?</p>
  <p>EDIT2:<br>
  There was a missing 't' in the class name and hence it didn't match the name of the connection string.</p>
  <p>I does work as expected when provider is SQL Server Compact providerName=&quot;System.Data.SqlServerCe.4.0&quot;, but if I change it to providerName=&quot;System.Data.SqlClient&quot; I get an exception added below. Shouldn't regular SQL Server be able to create a database file also?</p>
  <blockquote>
  <p>A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)</p>
  <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p>
  </blockquote>