title: Why does the following error occur: "The attempt to attach to the database failed with the following information: Login failed for user 'x\x'.?
body: <p>In my VS 2015 ASP.NET project I can update my SQL Server Express database through Package Manager Console and it is populated correctly. However, when I try to refresh the Data Connection in Server Explorer in Visual Studio I get the following error:</p>
  
  <blockquote>
    <p>The attempt to attach to the database failed with the following information:
    Login failed for user 'x\x'.</p>
  </blockquote>
  
  <p>Moreover, when I run the application and I try to log in with credentials set in the database by the Seed method in the Migrations' Configuration file I get an yellow page with the following message:</p>
  
  <blockquote>
    <p><strong>Login failed for user 'x\x'.</strong></p>
    
    <p>SQLExpress database file auto-creation error: </p>
    
    <p>The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider 
    attempted to automatically create the application services database
    because the provider determined that the database does not exist. The
    following configuration requirements are necessary to successfully
    check for existence of the application services database and
    automatically create the application services database:</p>
    
    <ol>
    <li>If the application is running on either Windows 7 or Windows Server
    2008R2, special configuration steps are necessary to enable automatic
    creation of the provider database. Additional information is available
    at: <a href="http://go.microsoft.com/fwlink/?LinkId=160102" rel="nofollow">http://go.microsoft.com/fwlink/?LinkId=160102</a>. 
    If the
    application's App_Data directory does not already exist, the web
    server account must have read and write access to the application's
    directory.  This is necessary because the web server account will
    automatically create the App_Data directory if it does not already
    exist. </li>
    <li>If the application's App_Data directory already exists, the web
    server account only requires read and write access to the
    application's App_Data directory. <br /> This is necessary because the web
    server account will attempt to verify that the Sql Server Express
    database already exists within the application's App_Data directory.
    Revoking read access on the App_Data directory from the web server
    account will prevent the provider from correctly determining if the
    Sql Server Express database already exists. This will cause an error
    when the provider attempts to create a duplicate of an already
    existing database. Write access is required because the web server
    account's credentials are used when creating the new database. </li>
    <li>Sql
    Server Express must be installed on the machine. </li>
    <li>The process identity
    for the web server account must have a local user profile. See the
    readme document for details on how to create a local user profile for
    both machine and domain accounts.</li>
    </ol>
  </blockquote>
  
  <p>My connection string is as follows:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="Users" connectionString="Data Source=.\SQLExpress;Initial Catalog=Reg;Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>This happened after a deployment to the local IIS Server and the creation of a new user for the login <strong>IIS APPPOOL\DefaultAppPool</strong>. After that I deleted the database I was using for debug and tried recreating it from the .mdf file in my App_Data folder. Which seemed to be impossible. I cannot understand why my Windows Domain\User login keeps failing since then. Interestingly, test projects I create with new databases are working OK, while the old ones crash.</p>
  
  <p>I couldn't find any compatible answer by now. What could it be?</p>
  
  <p>Thank you!</p>