Restore Database from MDF file without LDF

  • I saw one Message posted by Mr. raino clearly explains about how to restore database only with the MDF file.But its showing error while executing the query.can u please reply me when you see this msg

    Query I tried

    dbcc traceon(3604)

    dbcc rebuild_log ('Training','Training_Log')

    =================Error================

    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    Server: Msg 5105, Level 16, State 2, Line 2

    Device activation error. The physical file name 'Training_LOG' may be incorrect.

    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    ========================================

    Full Query you have posted

    =============================================

    shutdown sql

    move the current database file or rename it

    restart sql server

    create a new database of the same name and log file and location as the old database and log file

    get rid of the old database.

    you may be able to right click delete it in this situation or used sp_removedb

    create a new database of the right size and shape with correct log and data file locations

    stop sql

    rename the new databases.mdf or delete it if you don't have enough space - do not touch the .ldf

    move back in the old database .mdf file or rename it back again

    restart sql server

    it should come up suspect

    --------------------------------

    1. From a query window, set the status so that you can update the system

    tables by running the following query:

    use Master

    go

    sp_configure "allow", 1

    go

    reconfigure with override

    go

    2. Then set the status of the DB that is giving you the problem (XXXXX) into

    Emergency Mode by running the following query:

    update sysdatabases set status = 32768 where name = '<DBName>'

    go

    checkpoint

    go

    shutdown with nowait

    go

    3. Go into the data directory (MSSQL7\DATA) and rename the log file associated

    the DB in question (XXXX.ldf) to some

    temporary name, such as XXXX.TMP.

    4. Exit the query window.

    5. Then start up SQL Server from a DOS command window by issuing:

    sqlservr -c -T3608 -T4022.

    6. Bring up another query window and verify that the DB is in emergency mode

    by issuing:

    select Name, Status from Sysdatabases where name = '<DB_Name>'

    7. Verify that the status is 32768. If it is, then issue the query:

    dbcc traceon(3604)

    dbcc rebuild_log ('<DB_Name>','<log_filename>') <--- You will need

    the quotation marks

    REBUILD_LOG should take less than 5 minutes even on a very large

    database. It should complete with the message

    DBCC execution completed

    8. Take the database out of bypass recovery mode by issuing the command

    update sysdatabases set status = 0 where name = '<DBName>'

    9. Exit the query window and then shutdown (Ctrl-C in the DOS window) and

    restart SQL server. Verify the status of the

    database by running DBCC NEWALLOC and DBCC CHECKDB on the database.

    ===============================================================

  • Try

    dbcc rebuild_log ('Training', 'c:\Training_Log.ldf')

     

  • I have tried but its showing error.If try to open the created Database from enterprise manager its showing the error.Iam unable to expand the created Database

  • The information you posted looks somewhat dated (6.5 I'm guessing?).  What about simply using the sp_attach_single_file_db method described in Books On-Line?  One caveat:  attach single file will only work if the original database was shut down cleanly with no users or pending transactions.  But this seems a lot simpler and more straightforward than what you're trying to do. 

    Hope this helps. 

    My hovercraft is full of eels.

  • we have sql 2005 and cannot get these commands to work.  I have no idea what to next try.

     

    same issues w/ database and log are not properly connected.

     

  • Here is the situation:

    > C drive containing the SQL server 2005 is gone

    > D drive for data is available

    > E drive for logs is GONE

    > no backup of mdf nor the ldf file

    current dondition:

    > a new sql needs to be rebuilt

    > the MDF files need to be restored

    All the attach various commands are not the options because the DBs where shutdown ungracefully.

    So, here is the Q.

    How, to restore an MDF file on the new sql server without the original ldf file.

    thx

    JohnE

    Cheers,
    John Esraelo

  • try this.

    sp_attach_single_file_db @dbname= 'dbname' ,@physname= 'physical_name'

    but, make sure database got only one .mdf file or say datafile. This command doesnot work with multiple data files.

    SQL DBA.

  • This should work.

    Reinstall SQL 2005 at the same version level (SP1 or not).

    Right click Databases....click attach.

    Click Add and Point to MDF file.

    Create new ldf file

    Hit Ok.

    You will then have to recreate any logins needed for that db in your SQL instance.

    This is not very granular but I am running on empty for time. Good luck...this should work.

  • I am getting following errro when executing:

    DBCC REBUILD_LOG('dbname,'dbname_Log.LDF')

    ERROR:

    Server: Msg 5030, Level 16, State 1, Line 1

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

    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    anyone have any idea why i am getting this locked error and how to resolve it.

    my db got stuck now. can't do repeat the process either.

    any answer greatly appreciate.

  • thanks brother i solve my problem. I am thankful to you from core of my heart. You r very Genius. May God you live long.

  • Thx every1.

    its a gr8 forum.

    this article helped me alot. Today my DB went down and with the help of this i cld recover in 10 mins

    Gr8 thx.

    Cheers,

    Gunjan

  • Very nice solution i tried it and found it nice, specially when ldf file is missing

  • If you are facing corruption issues in your SQL Server database then you can use SQL recovery software which is especially designed for corrupted or damaged MDF file that can help you to easily repair and recover SQL database such as tables, triggers, functions, stored procedures and views etc. It also provides free demo facility, so you can download this tool from here:

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply