G D
G D

Reputation: 41

Sql Server Transaction Log Reader

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

Upvotes: 4

Views: 5762

Answers (4)

user2091150
user2091150

Reputation: 998

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

Upvotes: 1

Ardalan Shahgholi
Ardalan Shahgholi

Reputation: 12575

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

Upvotes: 0

Ivan Stankovic
Ivan Stankovic

Reputation: 1602

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

Upvotes: 3

usr
usr

Reputation: 171246

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.

Upvotes: 0

Related Questions