SQL SERVER – Fix : Error Msg 1813, Level 16, State 2, Line 1 Could not open new database ‘yourdatabasename’. CREATE DATABASE is aborted.

Fix : Error Msg 1813, Level 16, State 2, Line 1
Could not open new database ‘yourdatabasename’. CREATE DATABASE is aborted.

This errors happens when corrupt database log are attempted to attach to new server. Solution of this error is little long and it involves restart of the server. I recommend following all the steps below in order without skipping any of them.

Fix/Solution/Workaround:

SQL Server logs are corrupted and they need to be rebuilt to make the database operational.
Follow all the steps in order. Replace the yourdatabasename name with real name of your database.
1. Create a new database with same name which you are trying to recover or restore. (In our error message it is yourdatabasename). Make sure the name of the MDF file (primary data file) and LDF files (Log files) same as previous database data and log file.

2. Stop SQL Server. Move original MDF file from older server (or location) to new server (or location) by replacing just created MDF file. Delete the LDF file of new server just created.

3. Start SQL Server. Database will be marked as suspect, which is expected.

4. Make sure system tables of Master database allows to update the values.
USE MASTER
GO
sp_CONFIGURE 'allow updates', 1
RECONFIGURE WITH OVERRIDE
GO

5. Change database mode to emergency mode.
–Following statement will return the current status of the database
SELECT *
FROM sysdatabases
WHERE name = 'yourdatabasename'

—-Following statement will update only one row in database
BEGIN
UPDATE
sysdatabases
SET status = 32768
WHERE name = 'yourdatabasename'
COMMIT TRAN

6. Restart SQL Server (This is must, if it is not done SQL Server will through an error)

7. Execute this DBCC command in query window of Management Studio, this will create new log file. Keep the name of this file same as LDF file just deleted from new server :
DBCC TRACEON (3604)
DBCC REBUILD_LOG(yourdatabasename,'c:\yourdatabasename_log.ldf')
GO

DBCC accepts two parameters : first parameter is database name and second parameter is physical path of the log file. Make sure the path is physical, if you put logical file name it will return an error.

8. Reset the database status using following command.
sp_RESETSTATUS yourdatabasename
GO

9. Turn off the update to system tables of Master database running following script.
USE MASTER
GO
sp_CONFIGURE 'allow updates',0
RECONFIGURE WITH OVERRIDE
GO

This should be resolve the problem mentioned above. I always check consistence of the database as well as I reset the status of the database to original status.

10. Reset the database status to previous status
–Following statement will update only one row in database
BEGIN
UPDATE
sysdatabases
SET status = (value retrieved IN first query OF STEP 5)
WHERE name = 'yourdatabasename‘
COMMIT TRAN
GO'

Note : If during steps 8, 9 , 10 if there is error if database is in use.
Set the database to status single user.
sp_DBOPTION 'yourdatabasename', 'single user','true'
Once the steps 8,9,10 are completed if database is not already in multi user mode run this script.
sp_DBOPTION 'yourdatabasename', 'single user','false'
If there is any issue while doing above process to fix the error let me know. Make sure that you have done all the steps in order and restarted SQL Server where it is mentioned.

Reference : Pinal Dave (http://blog.SQLAuthority.com), BOL (many topics)

About these ads

70 thoughts on “SQL SERVER – Fix : Error Msg 1813, Level 16, State 2, Line 1 Could not open new database ‘yourdatabasename’. CREATE DATABASE is aborted.

  1. You REALLY saved my butt with this fix! A friend of mine comes onto your sight for tips, fixes and the like and told me I should see if you had a fix for this. Sure enough, you did! You have helped us out tremendously! Thanks again! Keep up the great work!

  2. Hi Pinal,

    Thanks for the script, you are a life saver :D

    Just found couple of typo FYI

    1. It should be RECONFIGURE not RECONFIGIRE
    2 REBUILDLOG is REBUILD_LOG

    But gain, Thanks a million!

    Mick

  3. Hi Pinal,

    While trying to attach Production (SQL2K) 20 datas and 2 logs to our Sandbox (SQL2K5) using the following script, I received an error… Can you please give me some suggestion on what might be wrong to my script?

    USE [master]
    GO
    CREATE DATABASE [SBX] ON
    ( FILENAME = N’F:\DATA\SBXDATA1\SBXDATA1.mdf’ ),
    ( FILENAME = N’G:\LOG\SBXLOG1\SBXLOG1.ldf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA10\SBXDATA10.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA11\SBXDATA11.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA12\SBXDATA12.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA13\SBXDATA13.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA14\SBXDATA14.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA15\SBXDATA15.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA16\SBXDATA16.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA17\SBXDATA17.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA18\SBXDATA18.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA19\SBXDATA19.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA2\SBXDATA2.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA20\SBXDATA20.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA3\SBXDATA3.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA4\SBXDATA4.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA5\SBXDATA5.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA6\SBXDATA6.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA7\SBXDATA7.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA8\SBXDATA8.ndf’ ),
    ( FILENAME = N’F:\DATA\SBXDATA9\SBXDATA9.ndf’ ),
    ( FILENAME = N’G:\LOG\SBXLOG2\SBXLOG2.ldf’ )
    FOR ATTACH
    GO
    if exists (select name from master.sys.databases sd where name = N’SBX’ and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [SBX].dbo.sp_changedbowner @loginame=N’ENTPRO\conjai’, @map=false
    GO

    Error message:

    Msg 1813, Level 16, State 2, Line 1
    Could not open new database ‘SBX’. CREATE DATABASE is aborted.
    Msg 3456, Level 21, State 1, Line 1
    Could not redo log record (73574:26706:79), for transaction ID (0:766408492), on page (1:7487504), database ‘SBX’ (database ID 5). Page: LSN = (73573:137222:224), type = 1. Log: OpCode = 6, context 2, PrevPageLSN: (73574:23272:17). Restore from a backup of the database, or repair the database.
    Msg 3313, Level 21, State 2, Line 1
    During redoing of a logged operation in database ‘SBX’, an error occurred at log record ID (73574:26706:79). Typically, the specific failure is previously logged as an error in the Windows Event Log service. Restore the database from a full backup, or repair the database.

    Thanks! I appreciate your help.

    -Jaideep

  4. This does not work in SQL Server 2005. I tried to update the sysdatabases table and it gave me error:

    ‘Ad hoc updates to system catalogs are not allowed.’

    I’m wondering if there is another alternative to recover an .MDF file without the log.

    -jorge

  5. I try to update sysdatabases. I get an error stating “Update sysdatabase fails because it can not update derived or constant field.” Why do I get this message? Appreciate for your help.

  6. Hi

    I understand the use of sp_resetstatus but as silly as it sounds I cannot locate ‘sp_resetstatus’ on the server, if I try from a command line, not found etc. Is there a download for this tool? (I don’t know SQL much at all) I have searched all over….

  7. Hi Pinal,

    Great work helped heaps with one of our clients.

    Not sure if due to different flavour of SQL but found a few glitches.

    Step 5 & 10 needed BEGIN TRAN not just BEGIN
    Step 10 needed to be run prior to step 9 or could not update

    I was folowing your steps religiosly and got to step ten and realised I did not know value from step 5 (OOPS!). Fortunately had old copy of DB as different name.

    Many thanks.

  8. I ran into this problem last night and was able to restore my databases on a SQL Server 2005 install by following these steps:

    1. Move mdf and ndf files to another directory (Data_old)
    2. Create a database with the same name and same file names and locations as the original databases. (this only applies to the mdf and ndf files the log file can go anywhere)
    3. Stop the SQL Server service.
    4. Overwrite new mdf and ndf files with the original ones.
    5. Start SQL Server.
    6. Run this script (Set the @DB variable to the name of your database before running):

    Declare @DB sysname;
    set @DB = ‘DBName';
    — Put the database in emergency mode
    EXEC(‘ALTER DATABASE [' + @DB + '] SET EMERGENCY’);
    — Set single user mode
    exec sp_dboption @DB, ‘single user’, ‘TRUE';
    — Repair database
    DBCC checkdb (@DB, repair_allow_data_loss);
    — Turn off single user mode
    exec sp_dboption @DB, ‘single user’, ‘FALSE';

    I got an error stating that the log file did not match the data file. You can ignore this as we are rebuilding the log file.

  9. Hi Pinal,

    I tried this solution and got the db backup, but for some reason, the ldf couldn’t be found under ‘Properties>Files’. When I tried to do a shrink log file, it displayed the mdf instead of the ldf??!! The funny thing is, at first I was able to see the tables, but after 5 minutes, I was not able to access the db anymore! I got the following error:

    “Error 945: Database cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server error log for details”

    Hence I lost my db. :(

    Any insight or suggestions on what happened would be much appreciated. :)

    Thanks,
    Mary

  10. There is fine tool-sql mdf recovery,repair data from corrupted databases in the MS SQL Server format (files with the *.mdf extension), can process huge databases, their file size can reach 16 TB, supports data extraction via the local area network, you can save recovered data as SQL scripts, it is also possible to split data into files of any size, can save extracted information directly to the SQL server. It allow to recovery SQL Server faster.

  11. I had this same error. Turns out the mdf file was READ ONLY. After unchecking READ ONLY, I was able to attach my database on SQL 2005 SP2.

  12. Hi, I experience the same problem as described and I able to recover the database using the step recommended by Howard above. The database is working for a while.

    However, when i try to connect the database from my program, i encountered the following error:

    Msg 211, Level 23, State 51, Line 1
    Possible schema corruption. Run DBCC CHECKCATALOG.
    Msg 0, Level 20, State 0, Line 0
    A severe error occurred on the current command. The results, if any, should be discarded.

    Trying to run the DBCC CHECKCATALOG return no error.
    Any idea?

    Thx.

  13. Hi,
    THANKS! You saved my life!!!!

    Just one thing:
    Instead of point 10, I run

    sp_DBOPTION ‘yourdatabasename’, ‘dbo use’, ‘false’

    and

    sp_DBOPTION ‘yourdatabasename’, ‘single user’, ‘false’

    Ciao!

  14. Hi,

    Thank you very much for this procedure – I have successfully implemented on a damaged DB.

    Just for the records, this procedure also works on MSSQL 2000.

    Thanks
    Patrick

  15. I got this error when attaching a db that has multiple log files, can I do the same process? Should I add the additional log file when I create the new db?

  16. At:

    DBCC TRACEON (3604)
    DBCC REBUILD_LOG(yourdatabasename,‘c:\yourdatabasename_log.ldf’)
    GO

    I get an error:

    The database could not be exclusively locked to perform the operation.

    I’ve tried forcing the db into Single User mode and still nothing. The log does not get created.

    Any ideas?

  17. THANK YOU!!!!!!!!!!!!! I LOVE YOU MAN!!!!!!!!!!!!! You saved my life. You are AWESOME AND DESERVE A GOLD STAR!!! If I knew your address I would send you cookies and wine and some other goodies.

  18. I have problem with MSSQL, i can’t attaching the DB… the error massege
    Error 1813: Could not open new database ‘name of database’. CREATEDATABASE is aborted. Device activiation error. The physical file name ‘c:\program files\Microsoft SQL Server\MSSQL\data\name of database_log.LDF’ may be incorrect.
    please hel[ me………

  19. I have problem with MSSQL, i can’t attaching the DB… the error massege
    Error 1813: Could not open new database ‘name of database’. CREATEDATABASE is aborted. Device activiation error. The physical file name ‘c:\program files\Microsoft SQL Server\MSSQL\data\name of database_log.LDF’ may be incorrect.
    please help me………

  20. hi,

    I encounter the following error when execute the steps at

    DBCC REBUILD_LOG(‘Local1′,’c:\Local1_Log.ldf’).

    Error msg:
    Server: Msg 5180, Level 22, State 1, Line 1
    Could not open FCB for invalid file ID 0 in database ‘Local1′.

    Connection Broken

    I could not proceed, do you have any suggestion?
    Thx a lot

  21. Dear Pinal,

    Thank you very much for this article. I could save a lot of job details for a whole week in a technical company, who has not backed up their database for long time.

    This worked me fine.

    I appreciate you for writing these kind of stuff.

    – Thanks -

  22. Hi Pinal

    Thank you very much indeed for writing such a clear an concise article about a very technical matter. Well done :)

    Thank you

  23. The solution posted by Howard (1-apr-2008) worked for me on SQL 2008.

    I had also got the ‘Ad hoc updates to system catalogs are not allowed’ message with Pinal’s script

  24. Hi Pinal,

    thank you very much for this solution !!! It was very useful for us … and perhaps it is possible for you to integrate the things which Jim Rickards responses!

    Wish you success and all the best for 2010!

    Bob

  25. When I do step 10
    I got this message :

    Server: Msg 259, Level 16, State 2, Line 1
    Ad hoc updates to system catalogs are not enabled. The system administrator must reconfigure SQL Server to allow this.

    Please your advice.
    Thanks

  26. Hi,

    To fix this issue login with admin privilege and execute below statements:
    SP_CONFIGURE ‘ALLOW UPDATES’, 1
    GO
    RECONFIGURE WITH OVERRIDE
    GO

    Regards,
    Pinal Dave

    • I am logged in as user sa still it gives me error while updating sysdatabases as “Ad hoc updates on system tables are not allowed”.

      Due to this i cannot set my database in emergency mode, my production database’s log file is corrupted and it is not allowing me to attach mdf file to create .ldf file.

      I tried the process mentioned by you but updating system table is not allowed, i tried in sql server management studio express 2005 and also in sql server edition 2005 but same error is popped out.

      Please can u help me to re-build ldf file since it is my production database and it needs to be sorted out fast.

      Your response will be appreciated………..

      Thanks in advance.

  27. Hi,

    This is simply great!!
    Your solution helped us to recover from a serious matter.
    Really thx a lot.

    Keep up the good work pal.

    Regards,
    Dinesh Hettiarachchi.

  28. Hi Pinal,

    Followed steps above – However when I try and query data table I receive error below

    Server: Msg 823, Level 24, State 2, Line 1
    I/O error (torn page) detected during read at offset 0x0000005ec80000 in file ‘C:\Program Files\Microsoft SQL Server\MSSQL\data\Deal.MDF’.

    Connection Broken

    If I try and open tables through Enterprise Manager Receive message

    Error 601 Could not continue scan with NOLOCK due to data movement

    Would you have any ideas ?

    Thanks

    • Hi, I have the same problem…did you get any answeer for that? if so, please share it…thanks in advance.

      Best Regards!
      Jesus

  29. Dear Pinal Dave,

    I’m sorry, please help me.

    When I do step ‘—-Following statement will update only one row in database’

    I found message “Msg 259, Level 16, State 1, Line 3
    Ad hoc updates to system catalogs are not allowed.”

    I don’t know what ‘s happen?

    Best regards,
    Surachai S

  30. You are wonderful gift from god. My database back, for those who have errors this solutions is applicable in SQL Server 2000

  31. Hi,

    I am logged in as user sa still it gives me error while updating sysdatabases as “Ad hoc updates on system tables are not allowed”.

    Due to this i cannot set my database in emergency mode, my production database’s log file is corrupted and it is not allowing me to attach mdf file to create .ldf file.

    I tried the process mentioned by you but updating system table is not allowed, i tried in sql server management studio express 2005 and also in sql server management studio 2005 but same error is popped out. I also tried by creating a user with all privileges but still i didn’t work

    Please can u help me to re-build ldf file since it is my production database and it needs to be sorted out fast.

    Your response will be appreciated………..

    Thanks in advance.

  32. I m using sql_2008
    When I run this stmt.
    DBCC TRACEON (3604)
    DBCC REBUILD_LOG(Campus,’D:\Campus_log.ldf’)
    I got error

    DBCC execution completed. If DBCC printed error messages, contact your system administrator.
    Msg 2526, Level 16, State 3, Line 2
    Incorrect DBCC statement. Check the documentation for the correct DBCC syntax and options.

    Do you have any solution???
    Thank in advance

  33. We are SQL server 2000 with SP4 patch. On one of my database whenever we run a select query we get following error
    Server: Msg 823, Level 24, State 2, Line 1
    I/O error (bad page ID) detected during read at offset 0x0000005ec80000 in file ‘D:\Program Files\Microsoft SQL Server\MSSQL\Data\MSSQL\Data\MediaBin Repository_Data.MDF’.

    Connection Broken
    We had tried checkdb with repair allo data loss but did not help. I don’t have good backup also.
    Please suggest

    Thank you

  34. We are using SQL server 2000 with SP4 patch. On one of my database whenever we run a select query we get following error
    Server: Msg 823, Level 24, State 2, Line 1
    I/O error (bad page ID) detected during read at offset 0x0000005ec80000 in file ‘D:\Program Files\Microsoft SQL Server\MSSQL\Data\MSSQL\Data\MediaBin Repository_Data.MDF’.

    Connection Broken
    We had tried checkdb with repair allow data loss but did not help. I don’t have good backup also.
    Please suggest

    Thank you

  35. We were getting the following error:

    Could not open FCB for invalid file ID 0 in database ‘Local1′.

    Turns out that after running:

    SELECT *
    FROM sysdatabases
    WHERE name = ‘yourdatabasename’

    the database (MDF) file we thought was mounted was not, so we stopped the SQL services and renamed the file to match the one in the record produced by the query directly above this paragraph.

    Also, we executed step number 10 before 9 because of a permission issue.

    Thank you. Om Shanti Om.

    ref:wavedrop

  36. Hi dave,
    I could solve just by going through the first three steps.
    Create a new database with same name which you are trying to recover or restore. (In our error message it is yourdatabasename). Make sure the name of the MDF file (primary data file) and LDF files (Log files) same as previous database data and log file.

    2. Stop SQL Server. Move original MDF file from older server (or location) to new server (or location) by replacing just created MDF file. Delete the LDF file of new server just created.

    3. Start SQL Server

  37. Thank you so much for this fix it tip, my client could not work for over a week because of the database crash, six months of data loss was at at stake.

  38. Hi Pinal,

    I am using SQL Server 2008 R2.

    I do not have any backup. due to some hardware issue the server got shut down abruptly. now that the server is up but there is issue with SQL server.
    i have the .mdf file but unable to connect. I followed the above mentioned steps but no success…

    infact during step 5 while updating the status i get the following message.
    “Ad hoc updates to system catalogs are not allowed.”.

    Kindly help..my butt is on fire now..

  39. on step 5, get an error:
    “Ad hoc updates to system catalogs are not allowed.”.
    i couldn’t advance…help please…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s