Sql Server Transaction Log Reader

5.4k Views Asked by At

Is it possible to open a sql server transaction log file with some type of a stream reader object?

I've tried in C# a variety of ways but the database appears to be opening the .ldf file with an explicit lock and even though I only want to read the file it is not possible while the database is running.

Opening the file while the database is closed is not what I'm looking for, I need to be able to read the transaction log in stream. I have a rough sketch of the file layout but right now I'm stuck being able to even attach.

Anyone know of any config options or other methods?

Thanks! -G

4

There are 4 best solutions below

3
On

You can read the log contents in great detail and at the lowest level by using the fn_dblog function. It requires SQL Server to be online and the database to be ONLINE.

0
On

You can, but since access to open files is restricted by Windows you need direct access via NTFS or Volume Shadowcopy Service. Both require administrator privileges so any application will require it. Also you should send CHECKPOINT command to your database to read latest data (it commands server to update files from database in memory). Better find solution that will be able to read opened database. For example Devart's DBForge or TransactionLogReader Pro

0
On

Use this command :

Select * from ::fn_dblog(null,null)

And for more information see this link : How Do You Decode A Simple Entry in the Transaction Log

2
On

It is possible to read both online transaction log (LDF) and transaction log backups using ApexSQL Log API. You can read an LDF file directly from your .NET application. Also, there are no locks during the reading process of a transaction log

Disclaimer: I work as a Product Support Engineer at ApexSQL