?
Solved

Attach Database without Log File - SQL 2005

Posted on 2008-11-14
3
Medium Priority
?
2,279 Views
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?
0
Comment
Question by:staugust
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
pjcoole earned 2000 total points
ID: 22963393
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
0
 

Author Comment

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

Assisted Solution

by:pjcoole
pjcoole earned 2000 total points
ID: 22970940
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 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