Cannot reattach db after moving

  • This is very odd! I detached several databases on a new install of sql2005 sp2 in order to meve them to their proper folders. Even though the files just went from the root of the dir down one level, When I reattach them, I get error 5173. The db consists of one .mdf and one .ldf file, so its not complicated. I tried deleting the .ldf file and letting sql create a new one, but it places the new .ldf file in the old location, not where I want it.

    Any ideas would be greatly appreciated! 🙂

  • Instead of using SSMS...use Query window to attach the db...

    If you have already deleted the log .ldf file then you try with

    ATTACH_REBUILD_LOG option...check BOL for syntax...

    CREATE DATABASE ...

    ATTACH_REBUILD_LOG

    I was thinking you were using SQL 2005 but if you are using SQL 2000

    You can use DBCC REBUILD_LOG command...

    Stop the Sql SERVICE and delete the .LDF file and bring the sql online your db will be in suspect mode...

    use the DBCC REBUILD_LOG log to rebuild the log where ever you want...

    MohammedU
    Microsoft SQL Server MVP

  • Did you provide new path for the ldf file?

    By the way, would it better to post your question in SQL 2005 folder since your question is SQL 2005 related?

  • Thank you for your reply!

    I did try using code that I had used in sql 2k days, but received the same error:

    Select @sql='

    EXEC sp_attach_db @dbname = N'''+@db+''',

    @filename1 = N''d:\data1\data\'+@db+'.mdf'',

    @filename2 = N''d:\log\data\'+@db+'_log.ldf'''

    exec (@sql)

    I passed in the db name and all was usually well. I will try using the create db version and see what happens

  • Remove the line related to the path of log file.

    After running your script, a new log file will be automatically created in the same folder of the data file.

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

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