Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework Code First ignoring connection string, using IIS instead
    primarykey
    data
    text
    <p>I have a web app that I've created using Entity Framework Code First. In setting it up I have managed to match my DB connection string to my DBContext by specifying the full namespace and class of the DBContext as the name of the connection string.</p> <pre><code>&lt;add name="MyClassProject.EfDbContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=true;User Id=MyUsername;Password=MyPassword;" providerName="System.Data.SqlClient"/&gt; </code></pre> <p>Initially when I set up the project, I just had it created in c:\inetpub\wwwroot, and just ran it through Visual Studio. Everything worked fine.</p> <p>Now I'm trying to have the code build to a separate website folder, and have the website run as it's own website and app pool in IIS. I've set up the website, and my hosts file but when I went to run it I received the following error.</p> <blockquote> <p>Cannot open database "MyDatabase" requested by the login. The login failed.</p> <p>Login failed for user 'IIS APPPOOL\MyAppPool'.</p> </blockquote> <p>I'm wondering why this is happening, as I seem to be specifying the security username and password to use for the DB in my connection string....so why is it trying to connect as the app pool that my website is running in?</p> <p>Also, how can I fix this, without having to give MyAppPool (or Network Service if I changed it to that) DB permissions in SQL Server?</p> <p><strong>Update:</strong> I should've mentioned that I initialise my DBContext class using:</p> <pre><code>namespace MyClassProject { public class EfDbContext : DbContext { public EfDbContext() : base ("MyDatabase") { } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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