locked
Why is application trying to create ASPNETDB_TMP.MDF? RRS feed

  • Question

  • User966057038 posted

    Hi everyone,

    I'm using the new ASP.NET Identity to manage my user roles and logins. In my SQL database I have all the necessary tables like AspNetRoles, AspNetUsers, AspNetUserRoles, etc. I am not referencing App_Data\ASPNETDB.MDF in my web.config or anywhere else in my application code. The application runs fine in my DEV environment: new users that I create are added to the AspNetUsers table, etc.

    1. However, if I remove ASPNETDB.MDF and aspnetdb_log.ldf from my App_Data folder, then build and run my application, a new ASPNETDB.MDF gets re-created in App_Data. Why is this happening?

    2. When I publish my application (but exclude ASPNETDB.MDF from the package), then run it in my UAT server, I get this error message when I launch the application:

    Server Error in '/UAT2' Application.
    
    An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 5123 and the SqlException message is: CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\INETPUB\WWWROOT\UAT2\APP_DATA\ASPNETDB_TMP.MDF'.
    CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
    Creating the ASPNETDB_8990329dd55744a8861bb265e1b3bb1d database...
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    SQLExpress database file auto-creation error: 
    
    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:
    
    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: http://go.microsoft.com/fwlink/?LinkId=160102. 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.
    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. 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.
    Sql Server Express must be installed on the machine.
    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.
    
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    
    Stack Trace: 
    
    
    [SqlExecutionException: An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 5123 and the SqlException message is: CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\INETPUB\WWWROOT\UAT2\APP_DATA\ASPNETDB_TMP.MDF'.
    CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
    Creating the ASPNETDB_8990329dd55744a8861bb265e1b3bb1d database...]
       System.Web.Management.SqlServices.ExecuteFile(String file, String server, String database, String dbFileName, SqlConnection connection, Boolean sessionState, Boolean isInstall, SessionStateType sessionStatetype) +4573672
       System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +1014
       System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +908
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

    It seems it is trying to re-create ASPNETDB_TMP.MDF and is encountering permissions issues.

    Why is it trying to create ASPNETDB_TMP.MDF?

    Here is my connection string in my web.config:

    <add name="DefaultConnection" connectionString="Data Source=COMPUTERNAME\SQLEXPRESS;Initial Catalog=DATABASENAME;Integrated Security=True" providerName="System.Data.SqlClient" />

    As you can see, there is no reference to the MDF file.

    Details of my application:

    • Visual Studio 2013
    • .Net 4.5
    • ASP.NET Web Forms
    • SQL Server 2014 Express

    Thanks for the help.

    Tuesday, December 30, 2014 10:00 PM

Answers

  • User-734925760 posted

    a new ASPNETDB.MDF gets re-created in App_Data. Why is this happening?

    Hi,

    So far as I know, the ASPNETDB.MDF gets automatically generated whenever you use one of the application services about profiles, membership, and so on. The generated .mdf file is a database (SQL 2005 express). So as you delete the ASPNETDB.MDF file, it will be re-created.

    There is a similar thread, please refer to the link below:

    http://forums.asp.net/t/1517995.aspx?what+is+ASPNETDB+MDF+what+s+its+importance+

    Hope it's useful for you.

    Best Regards,

    Michelle Ge

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 1, 2015 9:25 PM

All replies

  • User-734925760 posted

    a new ASPNETDB.MDF gets re-created in App_Data. Why is this happening?

    Hi,

    So far as I know, the ASPNETDB.MDF gets automatically generated whenever you use one of the application services about profiles, membership, and so on. The generated .mdf file is a database (SQL 2005 express). So as you delete the ASPNETDB.MDF file, it will be re-created.

    There is a similar thread, please refer to the link below:

    http://forums.asp.net/t/1517995.aspx?what+is+ASPNETDB+MDF+what+s+its+importance+

    Hope it's useful for you.

    Best Regards,

    Michelle Ge

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 1, 2015 9:25 PM
  • User966057038 posted

    Thanks Michelle Ge. I'm already using my SQL Express database to store my identity/role data, and it does get populated correctly whenever I add users, roles, etc. 

    My question was why is the app still re-creating ASPNETDB.MDF? How can I stop it from re-creating it or reading from it? I have already searched through all my code for references to it but find none. 

    Thanks.

    Friday, January 2, 2015 12:55 AM
  • User966057038 posted

    When I deployed my site, I went to IIS and found under "Connection Strings" the following:

    Default Web Site > Connection Strings > 

    Name: LocalSqlServer
    Custom:
    data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

    I'm not sure where this came from, because it certainly isn't in my web.config. In any case, I tried removing it but ended up with an error, so I put it back. Could this be the reason why ASPNETDB.MDB is still be accessed?

    Tuesday, January 6, 2015 2:36 AM