4

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

G D
  • 41
  • 1
  • 4
  • 1
    What exactly are you expecting to get out of the transaction log? You know that it stores (and not in a very readable way, either) the *result* of the commands, and not the commands themselves, right? – Aaron Bertrand Aug 10 '12 at 22:30
  • Yes, I understand what the trans log stores and it's purpose. It's precisely the result of those commands that I'm interested in. – G D Aug 10 '12 at 23:15

3 Answers3

3

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

Ivan Stankovic
  • 1,602
  • 18
  • 13
0

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.

usr
  • 168,620
  • 35
  • 240
  • 369
  • Agreed, I'm looking for a consistent method using a reader for a CDC-ish approach though. – G D Aug 11 '12 at 01:08
  • Interesting. And fn_dblog does not provide everything necessary? It can provide the raw log records, too. – usr Aug 11 '12 at 11:04
  • I've looked at it but, I'm looking some something a little less invasive that isn't going to hit the db engine. Reading the log should be the least impactful. – G D Aug 14 '12 at 19:52
0

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

Ardalan Shahgholi
  • 11,967
  • 21
  • 108
  • 144