• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2292
  • Last Modified:

Attach Database without Log File - SQL 2005

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?
  • 2
2 Solutions
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
staugustAuthor Commented:
(Step 5) How can I let the database attempt to be recovered and how do I go into suspect mode?
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now