Having trouble restoing DB through tsql?

Answered Having trouble restoing DB through tsql?

  • Tuesday, December 11, 2012 9:16 PM
     
      Has Code

    I tried restoring the database through SSMS, but I got an odd error, so I tried using tsql.

    When I run "Restore FileListOnly" to check if DB is valid, I get the following results, which makes me believe it's valid. These are not all the results, just the relevant info:

    RESTORE FILELISTONLY 
    FROM DISK = 'E:\database_backups\MyDB_12072012.bak' WITH FILE = 1
    

    LogicalName: MyDB_Data | J:\...\MSSQL10_50.SQLMMPAY\MSSQL\Data\MyDB.mdf

    LogicalName: MyDB_Log   | K:\...\MSSQL10_50.SQLMMPAY\MSSQL\Data\MyDB.ldf

    When I do the actual restore, I  get the following error:

    RESTORE DATABASE MyDB
    FROM DISK = 'E:\database_backups\MyDB_12072012.bak'
    WITH MOVE 'MyDB' TO 'C:\DataFiles\MyDB.mdf',
    MOVE 'MyDB_Log' TO 'E:\DataFiles\MyDB.ldf'
    Msg 3234, Level 16, State 2, Line 1
    Logical file 'MyDB' is not part of database 'MyDB'. Use RESTORE FILELISTONLY to list the logical file names.
    Msg 3013, Level 16, State 1, Line 1
    RESTORE DATABASE is terminating abnormally.

    What could be wrong?

    Thanks.

All Replies

  • Tuesday, December 11, 2012 9:22 PM
    Moderator
     
     

    Take a look at this helpful forum's post

    http://forum.lessthandot.com/viewtopic.php?f=22&t=8401

    scroll down to Denis Gobo post which is marked with 3 stars.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

  • Wednesday, December 12, 2012 4:05 AM
     
     Answered Has Code

    LogicalName: MyDB_Data
    | J:\...\MSSQL10_50.SQLMMPAY\MSSQL\Data\MyDB.mdf

    .....

    Msg 3234, Level 16, State 2, Line 1
    Logical file 'MyDB' is not part of database 'MyDB'. Use RESTORE FILELISTONLY to list the logical file names.
    Msg 3013, Level 16, State 1, Line 1
    RESTORE DATABASE is terminating abnormally.

    Hello,

    In the MOVE part you have to use the logical name and that's MyDB_Data, not only MyDB! =>

    RESTORE DATABASE MyDB
    FROM DISK = 'E:\database_backups\MyDB_12072012.bak'
    WITH MOVE 'MyDB_Data' TO 'C:\DataFiles\MyDB.mdf',
    MOVE 'MyDB_Log' TO 'E:\DataFiles\MyDB.ldf'


    Olaf Helper

    Blog Xing