Cannot reattach db after moving

  • 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 4 posts - 1 through 5 (of 5 total)

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