开发者

Read SQL Server 2005 ldf file

开发者 https://www.devze.com 2022-12-16 11:01 出处:网络
i will try to explain my question in details. In a program that i am writitng i need to read the content of log file for a certain database. I google a little bit and found开发者_开发问答 that ldf is

i will try to explain my question in details. In a program that i am writitng i need to read the content of log file for a certain database. I google a little bit and found开发者_开发问答 that ldf is binary file. But i was no able to find the format of the file or any tutorial showing how to read this file. I am writing the program on C# but any examples on any programing languages will be greatly appreciated.


The format of the log file is not documented and not public, even the commercial log readers will not pick up everything from the log - they most likely will of reverse engineered it or hired ex-SQL developers who know about it.

Before you concern yourself with decoding the physical file start by trying to decode the output from:

select * from ::fn_dblog(null,null)

That will get you a formatted output of the log and the log binary data in a field - even that is not trivial to decode. As well as the log file format, you will have to have a very indepth knowledge of SQL itself to understand the entries properly.

Overall - I think you are better off buying one of the existing commercial packages, because if you need to ask about the format - your internal knowledge of SQL is unlikely to be good enough.


Late one but hopefully useful…

There is a log reading API you might want to try ApexSQL Log API. This is a commercial tool but it has a free trial.

Other options are using undocumented functions such as DBCC LOG and fn_dblog.


I don't understand why do you need to implement this, but seems wrong, at least.

Every DBMS are implemented to keep you away from filesystem, as it's supposed to deal with operational system details and to provide concurrency, for instance. If you try to read that LDB from a running database you'll add weight in somewhere not designed to support it.

Maybe you just want to check who made some database update; in this case, you can to use triggers to log (into a regular database table), a timestamp and current user.

This option is far more simple than what you proposed and can be achieved in a documented way.


Use this command as @Andrew Said:

Select * from ::fn_dblog(null,null)

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


Try Sql Log Rescue from RedGate. If you do find how the file is formatted let the rest of us know.

0

精彩评论

暂无评论...
验证码 换一张
取 消