Error 9003 when attaching a database

Error 9003 when attaching a database

Problem

When attempting to attach a company database to SQL Server using SQL Server Management Studio you receive error 9003 with a message similar to this:

The log scan number %S_LSN passed to log scan in database '%.*ls' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup.

Cause

This can be caused when the database log file (.ldf) corrupt. SQL Server cannot attach a database file (.mdf) with a matching corrupt log file.

Solution

The best solution is to restore from a recent backup. However, if a recent backup is not available then you can delete the corrupted log file and then attach the database. SQL Server will then re-create the log file.

Note: It's possible that data loss will occur if you delete the log file so only perform this process if you don't have a recent backup.

To delete the log file

  1. In Windows Explorer navigate to the folder that contains the database files (.mdf and .ldf) that you are attempting to attach.
  2. Delete the .ldf file.
  3. Run SQL Server Management Studio.
  4. Right-click on Databases and select Attach.
  5. Click the Add button, select the .mdf file and click OK.
  6. On the Attach dialog, in the Database details section, select the log file (.ldf) and click Remove.
  7. Click OK to attach the database. A new log file will be created.

    • Related Articles

    • Database service not found

      Summary The instance of SQL Server for Solatech was not found on this computer. More Information When the Solatech Window Covering Software is installed it installs an instance of Microsoft SQL Server Express 2005. This instance of SQL Server is what ...
    • SQL Server not Accessible Error Message

      Summary You may receive the message that SQL Server is not accessible when trying to open your Solatech company.  Although there are various reasons for this error message, the two most common are that either SQL Server isn't running or that you have ...
    • SWCS 4.x can't access a SQL Server 2005 database

      Symptoms When you attempt to open a company file located on a server using SQL Server 2005 you receive the following error message: The company '...' is not a valid company or you don't have permission to access it. Check with your system ...
    • How to resolve the SQL Server Not Accesible Error Message

      Summary You may receive the message that SQL Server is not accessible when trying to open your SalesPRO company.  Although there are various reasons for this error message, the two most common are that either SQL Server isn't running or that you have ...
    • Error: A new company could not be created because the server... could not be verified

      Symptoms When a new company is created an error message similarly to the following is displayed and the new company is cannot be used: A new company could not be created because the server 'xxx' could not be verified. Cause This problem can occur if ...