Attach a database error 5173

  • We are trying to attach a database from another server.  We are running the same service pak as the other server.  The files were detached from the other server.  We have both the .mdf and .ldf files, we can verify the files.    However, when we try to attach the file we get the following error:

    Error 5173: Cannot associate files with different databases.

    Does anyone know why we would receive this error message or if we need to set some defaults prior to attaching the database?

    Any help would be appreciated.

    Thank You!

     

     

  • From knowledge base

    SQL Server does not allow you to attach a single file of a database that contains multiple files. The attach looks for all files that belong to the database during the attach and if it cannot find the files with the corresponding GUID, it fails the attach. Similarly, if you create a blank database with the same filenames and filegroups as the original database, replace some of the files, and then attempt to let SQL recover the database upon startup, recovery fails as indicated by the errorlog.

  • Does any one know of a workaround?

     

    Thanks

     

  • Are you sure that you have got all data files from the original db? Are you sure that your .mdf and .ldf files come from the same db? If the latter is not true, you can try attach only mdf file and new log will be created for you by sql server. If a datafile(s) is missing you should get a complete set of files and start again. If it's not possible you can try these steps to salvage your data:

    we've got only primary data file, all secondary files and log files are lost

         sp_attach_db doesn't work because it looks for all files that originally comprised db

             a) backup the file before going any further

             b) rename the file to filename_old

             c) create new db that has one file of the same physical name and size as our file

                (logical name of the file and name of db can be different from original)

             d) stop Sql server

      e) replace original file for mdf file of newly created db

             f) start SQL server

             g) in SQL Server logs are messages 'Log file does not match the primary file.',

                'Cannot associate files with different databases.' and db is suspect

             h) Set database in emergency mode:

     

                sp_configure 'allow updates', 1

                reconfigure with override

                go

                update sysdatabases

                set status = 32768

                where name = 'db_name'

                go

                sp_configure 'allow updates', 0

                reconfigure with override

                go

             i) Now Data should by accessible - Export data out of the database using bcp or DTS

             j) drop db created in step c

  • Hi,

    This is really a good way of attaching database that contains only MDF file. I have done this.. In this process I have a small doubt i.e; Can we get the storeprocedures and all the functions that we have written?

    Thank You

    Koti Reddy

  • sir my database is suspected giving error attatching a database error 5173

Viewing 6 posts - 1 through 5 (of 5 total)

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