Web application fail to start with a manual database definition

Problem

Web application do not start, generating a CREATE DATABASE error message

The error may occur when a database is copied from another source and the configuration files are edited to match the new database. Normally the configuration is setup by the publisher process, but it may be done manually i.e. during initial test of an installation.

The error message is similar to this:

AssertWeb Error: 0 : System.Data.SqlClient.SqlException (0x80131904): Cannot create file 'C:\Data\Site\Assert4#Database.mdf' because it already exists. Change the file path or the file name, and retry the operation.

CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

Solution

The error is is that database -filename, -logfilename, -name is not consistent with the database being attached to SqlServer by the application.

  1. If the database has been attached manually, detach it to permit the web application to attach it during startup.

  2. Delete the database log file *_log.ldf if it exists, since database files contain information on their previous location - probably paths not existing on a another computer.

  3. Verify that the definition in application file: C:\inetpub\wwwroot\AssertWeb\App_Data\server.config is correct regarding database name, database file and log file.