Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 EF 5 Debugging in VS 2010 against remote database
    text
    copied!<p>When I try to debug my MVC4/EF 5 app locally in VS2010, against a remote database, the following happens.</p> <p>Source of error (InitializeSimpleMembershipAttribute.cs):</p> <pre><code>using (var context = new UsersContext()) { if (!context.Database.Exists()) // &lt;-- Exception here! { // Create the SimpleMembership database without Entity Framework migration schema </code></pre> <p>Stack trace (only the first line):</p> <pre><code>[SqlException (0x80131904): Login failed for user 'mydb'.] </code></pre> <p>After debugging i find out that the following connectionstring is used:</p> <pre><code>"Data Source=localhost;Initial Catalog=mydb;Persist Security Info=True;User ID=mydb;Password=mydb;Application Name=EntityFrameworkMUE" </code></pre> <p>This is the real connectionstring in Web.Config:</p> <pre><code>&lt;add name="DefaultConnection" connectionString="Data Source=hostname.com;Initial Catalog=mydb;User ID=mydb;Password=mydb;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /&gt; </code></pre> <p>Code snippet from AccountModels.cs:</p> <pre><code>public class UsersContext : DbContext { public UsersContext() : base("DefaultConnection") { } public DbSet&lt;UserProfile&gt; UserProfiles { get; set; } } </code></pre> <p>Its quite apparent that DefaultConnection should be used, but along the way its modified...</p> <p>When I publish my site to the remote server, where the sql server is also hosted, everything works just fine.</p> <p>Solutions mentioned in other posts have not worked for me, such as naming the connection in Web.Config to the name of my DbContext class.</p> <p><strong>Edit - I've done some more experimenting...</strong></p> <p>This does not work:</p> <pre><code>public class UsersContext : DbContext { public UsersContext() : base(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString) { } public DbSet&lt;UserProfile&gt; UserProfiles { get; set; } } </code></pre> <p>But this does:</p> <pre><code>public class UsersContext : DbContext { public UsersContext() : base("Data Source=hostname.com;Initial Catalog=mydb;User ID=mydb;Password=mydb;MultipleActiveResultSets=True") { } public DbSet&lt;UserProfile&gt; UserProfiles { get; set; } } </code></pre> <p>I get the feeling my Web.Config isnt used/recognized when debugging locally.</p> <p>Help is still needed :-P</p>
 

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