INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips Forums!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Microsoft SQL Server: Setup and Administration FAQ
Recovering when LDF is lost/corrupted
Posted: 23 Mar 06
First attempt to use sp_attach_single_file_db
EXEC sp_detach_db @dbname = 'AdventureWorks';
EXEC sp_attach_single_file_db @dbname = 'AdventureWorks',
@physname = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf';
if this doesnt work then try the following:
(Ive used this script myself and found it a life saver, I believe it may have come from Jasper Smith, although I cant find an original ref)
1) Make sure you have a copy of your.MDF
2) Create a new database called fake (default file locations)
3) Stop SQL Service
4) Delete the fake_Data.MDF and copy your.MDF to where fake_Data.MDF used to be and rename the file to fake_Data.MDF
5) Start SQL Service
6) Database fake will appear as suspect in EM
7) Open Query Analyser and in master database run the following :
This will put the database in emergency recovery mode
sp_configure 'allow updates',1
reconfigure with override
update sysdatabases set
status=-32768 where dbid=DB_ID('fake')
sp_configure 'allow updates',0
reconfigure with override
8) Stop SQL Service
9) Delete the fake_Log.LDF file
10) Restart SQL Service
11) In QA run the following (with correct path for log)
12) Now we need to rename the files, run the following (make sure there are no connections to it) in Query Analyzer (At this stage you can actually access the database so you could use DTS or bcp to move the data to another database).
dbcc checkdb('fake') -- to check for errors
/* Make a note of the names of the files , you will need them
in the next bit of the script to replace datafilename and
logfilename - it might be that they have the right names */
alter database your
MODIFY FILE(NAME='datafilename', NEWNAME = 'your_data')
alter database PowerDVD301
MODIFY FILE(NAME='logfilename', NEWNAME = 'your_Log')
sp_dboption 'your','dbo use only','false'
13) You should now have a working database. However the log file will be
small so it will be worth increasing its size. Unfortunately your files will
be called fake_Data.MDF and fake_Log.LDF but you can get round this by
detaching thedatabase properly and then renaming the files and reattaching it.
14) Run the following in QA
--now rename the files then reattach
Back to Microsoft SQL Server: Setup and Administration FAQ Index
Back to Microsoft SQL Server: Setup and Administration Forum
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close