Our SQL Server 2012 Express server crashed and lost some data. We managed to rescue the main MDF, but can't find the LDF. Is there a way to get this information from the database MDF file or msdb, or temp mdfs that were found?
Sql-server – SQL Server: Get location of transaction log from MDF file
restoresql serversql-server-2012
Related Question
- Sql-server – How to rescue SQL Agent jobs from a set of detached master, model, mdb files
- Sql-server – SQL Server Restore DB from MDF file, lost LDF and DB was not cleanly shutdown
- Sql-server – How to attach an .mdf file that was not properly detached
- Sql-server – Disk Crashed, NDF(Index) file lost
- Sql-server – Is it possible to restore SQL Server DB from transaction log (no MDF)
- Sql-server – SQL Server MDF still has old values after update
- Sql-server – attach a damaged mdf file in SQL server
- Sql-server – Restoring MDF without LDF file
Best Answer
This is stored in a couple or locations in the MDF.
sysprufiles
- I've checked a few databases installed locally and found it on page 155 and page 153 of the ones I've checked. I imagine this will always be fairly early in the file but it doesn't appear to have a fixed location.sysfiles1
- which is reliably on page 32 for every database I have checked so far.The initial version of this answer used a hex editor to read it from the MDF.
Dan Guzman points out there is an undocumented DBCC command that is massively simpler.
Returns a result like
I was curious as to how that approach worked so looked at the activity in process monitor.
This ends up reading the file header (page 0), database boot page (page 9) and page 32 of the file.
I didn't see page 32 mentioned on either of the preceding pages so I think that page is hardcoded to contain the information rather than being looked up from them.