User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 375,221 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,273 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 654 | Replies: 3
Reply
Join Date: Apr 2008
Posts: 4
Reputation: dkerr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dkerr dkerr is offline Offline
Newbie Poster

query mdf directly?

  #1  
Apr 1st, 2008
Can I query a SQL Server 2000 mydatabase.mdf file directly via SQL? If so, how?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Egypt
Posts: 743
Reputation: RamyMahrous is on a distinguished road 
Rep Power: 3
Solved Threads: 54
Featured Poster
RamyMahrous's Avatar
RamyMahrous RamyMahrous is offline Offline
Master Poster

Re: query mdf directly?

  #2  
Apr 3rd, 2008
You should attach it first then query it..
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Reply With Quote  
Join Date: Nov 2007
Location: Jogja
Posts: 2,330
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 9
Solved Threads: 204
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Nearly a Posting Maven

Re: query mdf directly?

  #3  
Apr 4th, 2008
as ramy said, attach your current mdf file then you can do anything.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Apr 2008
Posts: 4
Reputation: dkerr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dkerr dkerr is offline Offline
Newbie Poster

Re: query mdf directly?

  #4  
Apr 4th, 2008
Ideally yes...but attaching wasn't easy in my case with a missing log file. Found this article on spaceprogram.com that solved my problem. Thanks for the help!!

Recovering from a deleted log file on SQL Server
Introduction
This document will give instructions on how to recover from a deleted database log file on Microsoft SQL Server. The database this was done on was SQL Server 7 with SQL Server 2000.

You will get a suspect beside the name of the database when this happens.

You may be interested in the document if one of the following happened:

You're log file got too big so you decided to shutdown SQL Server, then delete the log file.
Salvage data from a damaged SQL data (.MDF) file. ( Someone emailed about this ).
That's the only reason I can think of right now and that is the reason I have come to do figuring this out, so here goes.

Instructions
If you have a recent backup of the database, USE IT! Forget about this article and do a normal restore procedure. Otherwise read on.

First of all, you are SOL if you want a full recovery. You just can't get all the data back because the log file itself contained a lot of transactions that may never have made it to the data file.

So anyways, I read just about everything possible on this topic and nothing worked, I mean nothing. I tried going into emergency mode, running stored procedures that did squat, using sp_detach_db, then sp_attach_db, etc, even trying db_rebuild_log() (the rebuild_log thing seems to be an undocumented feature that someone must have figured out... easter egg?? not really since there are some serious warnings against using it, but hey, when you're in dire straits, you'll try anything once, right?).

This restore procedure doesn't seem to be formally documented anywhere. I guess you're just not supposed to be this stupid, but everybody makes mistakes don't they? And hey, I'm no DBA or anything! I just use the damn things. ;-)

Anyways, on to the guts of the article. I am trying to make this as simple as possible and pulling this from memory so if there is something I am missing, please don't hesitate to e-mail us at: <snipped>

There's one thing to note here and if someone could verify it, that would be great. First thing I'd like to verify is if you can just skip to step 9 right off the bat? So as soon as you get a suspect database, can you just start at step 9? Can someone please try that and let me know. SEE UPDATE: JAN. 6, 2003 BELOW

Backup the data (.mdf) file! Just in case. We take no responsibility for anything that happens following this procedure.
EXEC sp_detach_db 'dbname' -- this will detach the database from the server
Restart SQL Server
The database may still be seen in enterprise manager, but just ignore it.
Create a new database with the same name or a different name. You will have to use a different physical file name, which is fine.
Stop SQL Server.
Rename the new data file that was created to something else (ex: add.bak to the end)
Rename the old data file that you want to restore to the name of the newly created file (the same name as the file you changed in the step above)
Start SQL Server
Now the db will still be suspect but you now have a log file.
Switch to emergency mode on the database. You do this by doing the following:
Right click on the database root node in Enterprise manager and bring up the properties.
Under the Server Settings tab, check of "Allow modifications to be made directly to the system catalogs".
click ok
Now go to the master database and open the sysdatabases table.
Find the suspected database in here and modify the status column, setting it to: 32768. This will put it into emergency mode.
stop then start sql server
Now here's the tricky part and I'm not sure how this will work on a single install, i was lucky enough to have SQL Server 2000 installed. But anyways, open up the Import and Export Data (DTS) program from the start menu. And you want to copy data from the old database to a brand new one. Just copy tables and views.
And voila, this should work smoothly. Let me emphasize should.




Originally Posted by RamyMahrous View Post
You should attach it first then query it..
Last edited by peter_budo : Apr 5th, 2008 at 11:48 am. Reason: Keep It On The Site - Do not post asking for an answer to be sent to you via email or PM. Problems and their responses assist others who read them.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MS SQL Marketplace
Thread Tools Display Modes

Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 3:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC