Attach Database without Log File - SQL 2005

Posted on 2008-11-14
Last Modified: 2012-05-05
While trying to attach a Database without a logfile with the procedure sp_attach_single_file_db we get the following error message:

The log cannot be rebuilt because the database was not cleanly shut down.

The database is not detached, before the logfile hase been lost.

When we create a new Databse with the same name and path, stop the sql server, replace with the original .mdf and start the sql server, the Database is visible but there are no items in the tree.

While trying to use: ALTER DATABASE Databsename SET EMERGENCY
we get the error: Access denied.

What can we do?
Question by:staugust
    LVL 2

    Accepted Solution

    Try these steps.

    1 create a database with the same name in another directory as the one you're trying to attach
    2 re-create all filesgroups and files as necessary
    3 shutdown the server
    4 swap in the old mdf file and any ndf files
    5 bring up the server and let the database attempt to be recovered and then go into suspect mode
    6 put the database in single_user and emergency modes
    7  run DBCC CHECKDB (dbname, REPAIR_ALLOW_DATA_LOSS) which will rebuild the log and run full repair
    8  return database to online, multi_user mode

    Author Comment

    (Step 5) How can I let the database attempt to be recovered and how do I go into suspect mode?
    LVL 2

    Assisted Solution

    When you try to start the database it will try to recover on it own.  Then it will go into suspect mode because it knows something is wrong.  That is part of the startup process when starting up a database.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
    by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now