Search code examples
c#asp.net.netfilepublishing-site

The process cannot access the file \App_Data\ASPNETDB.MDF' because it is being used by another process.


When trying to publish our website on Windows Server 2008 R2, we are seeing the following error. Error 4 The process cannot access the file 'C:\Users\Student\Desktop\CSFP Front-End\App_Data\ASPNETDB.MDF' because it is being used by another process.
We don't understand what else could be using the data file. web.config looks like this

<connectionStrings>
    <add name="FBConnectionString" connectionString="Data Source=SERVER4;Initial Catalog=AITP;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Student\Desktop\CSFP Front-End\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True"/>
  </connectionStrings>
  <system.web>

It runs fine locally, and the roles and users work as well. "Build Web Site" also works just fine, but when we are trying to publish the website it throws the error. Any ideas?


Solution

  • while publish the project, first detach the database file. Then publish it will work fine. For detaching right click on App_Data->ASPNETDB.MDF, detach...