title: EF Code First - creating database - Login failed for user
body: <p>I originally had a EF code first set up that was connecting to an existing database. This was working fine.</p>
  
  <p>I then made a couple changes to a POCO and decided to have code first generate the new database for me.</p>
  
  <p>Getting error: Cannot open database \"MyDatabase\" requested by the login. The login failed.\r\nLogin failed for user 'DOMAIN\username'.</p>
  
  <p>I deleted the old database, but I did not change the connection string:</p>
  
  <pre><code>&lt;add name="MyDatabaseContext" connectionString="Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True;" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>I have a sql server 2008 instance on my local machine and my domain username is in "sysadmin" role.</p>
  
  <p>I tried various Database initializers and I get the same error for all. It is failing on the first query call, but code first does not create the database. I can point the connection string to a copy of the old database (before changes) and it will run fine, except that it is my old schema even though I specified the DropCreateDatabaseAlways initializer. This is not making sense, and not following what I experienced on my home machine working with code first.</p>
  
  <p>Using Visual studio 2012 and EF5.</p>
  
  <p>I need to be able to have code first generate a new database. What is going on?</p>