How to Fix SQL Server Error 1813 When You Attach a Database?
SQL Server error 1813 stops an attach with the text Could not open new database. You get 3 methods in this guide. Method 1 attaches the data file with a log rebuild. Method 2 repairs the database in emergency mode. Method 3 recovers the MDF file with PCVITA software. Copy your MDF and LDF files before any repair.
You attach an MDF file in SQL Server Management Studio and the window answers with error 1813. Object Explorer shows no database and your data stays out of reach.
This guide shows how to fix SQL Server error 1813 with 3 methods. Steps follow the Microsoft Learn pages on CREATE DATABASE and DBCC CHECKDB.
What Causes SQL Server Error 1813?
Error 1813 reads Could not open new database and CREATE DATABASE is aborted. SQL Server prints it last. Another message above it names the reason.
- Missing log file. Your LDF file sits in another folder or does not exist.
- Unclean shutdown. SQL Server stopped while the database was open so the log cannot be rebuilt.
- Damaged log file. Errors in the LDF file stop recovery at the attach.
- Missing data file. One NDF file of the database is not available.
Microsoft states that FOR ATTACH needs every MDF and NDF file. It rebuilds a missing log only for a read and write database that has one log file and shut down cleanly.
Microsoft names a restore from the last known good backup as the primary recovery route. Use the methods below when no backup exists.
Method #1: Attach With Log Rebuild (Free, T-SQL)
Use this method when the data files are complete and the database shut down cleanly. SQL Server creates a new log file of 1 MB in the default log folder.
- Copy the MDF and NDF files to a safe folder.
- Open a New Query window in SQL Server Management Studio.
- Execute the statement below with your database name and file path.
CREATE DATABASE SalesDB
ON (FILENAME = 'D:\Data\SalesDB.mdf')
FOR ATTACH_REBUILD_LOG;
- Refresh Databases in Object Explorer and open your database.
- Take a full backup because the rebuild breaks the log backup chain.
ATTACH_REBUILD_LOG works for read and write databases only. After an unclean shutdown the statement fails. Use Method 2 or Method 3 in that case.
Method #2: Repair in Emergency Mode (Free, Data Loss Risk)
Emergency mode gives a sysadmin read only access to a damaged database. DBCC CHECKDB then repairs it and rebuilds a corrupt log. Microsoft warns that the repair can cause data loss.
- Copy every MDF, NDF and LDF file to another disk first.
- Create a new database with the same name as the damaged one.
- Stop SQL Server and replace the new MDF file with your damaged MDF file. Delete the new LDF file.
- Start SQL Server and look for the SUSPECT state.
- Execute the statements below in a query window.
ALTER DATABASE SalesDB SET EMERGENCY;
ALTER DATABASE SalesDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DBCC CHECKDB (SalesDB, REPAIR_ALLOW_DATA_LOSS);
ALTER DATABASE SalesDB SET MULTI_USER;
- Execute
DBCC CHECKCONSTRAINTSand take a full backup right away.
A log rebuild removes the guarantee of transactional consistency. Check your tables and relationships. Microsoft does not document the file swap in step 3. It comes from DBA practice.
Method #3: Recover the MDF File With PCVITA Software (Paid Export)
Use this method when the attach fails and you cannot accept the data loss of a repair. PCVITA SQL Database Recovery Tool reads the damaged MDF file with its NDF files. PCVITA software shows every object and record before the export.
- No attach needed. The software opens the file directly so error 1813 never appears.
- Scan modes. Quick Scan handles normal damage and Advance Scan handles severe damage.
- Deleted data. Deleted records show in red and dropped objects come back with Advance Scan.
- Outputs. Export to a live SQL Server database, a SQL script or CSV files.
- Install PCVITA SQL Database Recovery Tool and click Open. Select the damaged MDF file.

- Select Advance Scan and tick Recover Deleted Objects for a heavily damaged file.

- Add your NDF files when the software does not detect them. Preview tables and procedures in the object tree.

- Click Export and select SQL Server Database. Create a new database or select an existing one.

The free demo exports 25 records per table. Check one table in the new database before you buy the full edition.
Which Method Fits Your Case?
| Method | Works When | Risk to Data | Cost |
|---|---|---|---|
| #1 Attach With Log Rebuild | Clean shutdown and all data files present | Breaks the log backup chain | Free |
| #2 Emergency Mode Repair | Log is damaged and shutdown was unclean | Rows and pages can be lost | Free |
| #3 PCVITA Software | Attach and repair fail | None to the original file | Free demo, $249 full |
Safe Handling Tips
- Copy first. Save the MDF, NDF and LDF files before every attempt.
- Read the first message. The line above error 1813 tells you which method fits.
FAQs About SQL Server Error 1813
What does SQL Server error 1813 mean?
Error 1813 states Could not open new database and CREATE DATABASE is aborted. SQL Server prints it after another message that names the real reason. Read the lines above error 1813 in the Messages pane.
Can I attach an MDF file without the LDF file?
Yes. Microsoft states that FOR ATTACH rebuilds a missing log for a read and write database with one log file when SQL Server shut down cleanly. Use FOR ATTACH_REBUILD_LOG when you want the rebuild in the statement.
What happens when the database did not shut down cleanly?
SQL Server cannot rebuild the log and the attach fails with error 1813. Use emergency mode repair or recover the data file with software.
Does ATTACH_REBUILD_LOG keep my log backups usable?
No. Microsoft states that the rebuild breaks the log backup chain. Take a full database backup right after the attach completes.
Can DBCC CHECKDB repair cause data loss?
Yes. REPAIR_ALLOW_DATA_LOSS can deallocate rows and pages and Microsoft calls it an emergency last resort. Restore from the last known good backup when you have one.
Which SQL Server versions does PCVITA SQL Database Recovery Tool read?
PCVITA SQL Database Recovery Tool reads MDF and NDF files of SQL Server 2000 to 2025. It detects the version on its own.
Does the free demo of PCVITA SQL Database Recovery Tool export data?
Yes. The free demo previews every object and exports 25 records per table. The full edition costs $249 for one licence.
Closing Words
Error 1813 only closes the attach. The message above it shows the cause. Attach with a log rebuild when the shutdown was clean and repair in emergency mode when it was not.
- Methods 1 and 2 use Microsoft commands and cost nothing.
- Method 3 recovers the data when both commands fail.