Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET retrieving data from nowhere
    primarykey
    data
    text
    <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">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">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("MoviesDBContex") { } } </code></pre> <p>and web.config contains</p> <pre><code> &lt;connectionStrings&gt; &lt;add name="MoviesDBContext" connectionString="Data Source=|DataDirectory|Movies.sdf" providerName="System.Data.SqlClient"/&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="System.Data.SqlServerCe.4.0", but if I change it to providerName="System.Data.SqlClient" 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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload