Restore MDF and LDF file

  • Hello. I am trying to restore and MDF/LDF file combo and am having trouble. If I try to attach I get a message "Cannot associate files with different databases". I think the problem is that I after backing up those files, we reinstalled SQL 7. Even though the server name and install directories are the same, it still won't work.

    Any ideas would be appreciated.

  • Are you attaching the db files to a db with the same name that it had before?

  • Yes, I am. Another problem is that the we never did a "detach". We just stopped the services and copied the MDF and LDF file.

  • Guess since you did not detach , it might not take the attach . I think u cannot attach if you did not detach the files. Maybe you can try to restore the backup's.

  • The database should be attached back as long as you properly shut down the services. Can you post statement/commands here to show how did you try to get the database back?

  • I tried:

    EXEC sp_attach_db @dbname = N'cpk',

    @filename1 = N'c:\MSSQL\Data\cpk_data.mdf',

    @filename2=N'c:\MSSQL\Data\cpk_log.ldf'

    I also tried it without the log file. Both times, I got the error.

  • Hi,

    Make sure the version of SQL Server is the the same as the one you are trying to attach to. That includes Service Pak updates.

    Good Luck.

  • I've notiched that sometimes sp_attach dosn't work.

    Maybe you could try the command:

    create database cpk on primary (filename='c:\mssql\data\cpk_data.mdf') for attach

  • tigersbh,

    Can you copy and paste the error messages from QA after your execute the sp_attach_db statement?

  • Yes, it's possible the service packs versions are different. I'll have to figure out what SP we had before.

    "create database cpk on primary (filename='c:\mssql\data\cpk_data.mdf') for attach" didn't work either. I still get:

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

    Cannot associate files with different databases.

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

    Device activation error. The physical file name 'D:\MSSQL7\data\DSM_CPKFinishing_be_Log.LDF' may be incorrect.

    Server: Msg 945, Level 14, State 1, Line 1

    Database 'DSM_CPKFinishing_be' cannot be opened because some of the files could not be activated.

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

    Could not open new database 'DSM_CPKFinishing_be'. CREATE DATABASE is aborted.

    Thanks for all of your replies.

  • NOTE: You might have noticed a discrepancy in the database names. The actual database name is "DSM_CPKFinishing_be". I shortened it to "CPK" in our discussions, but have always typed the full name when using the "attach" commands.

  • quote:


    Device activation error. The physical file name 'D:\MSSQL7\data\DSM_CPKFinishing_be_Log.LDF' may be incorrect.


    It seems log file 'DSM_CPKFinishing_be_Log.LDF' is not in directory ''D:\MSSQL7\data\'. Can you check that?

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

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