Solved

Transaction log and C#

Posted on 2014-04-12
3
924 Views
Last Modified: 2014-05-22
I have a requirement where i have to read a transaction log file of sql server in C#

1. To find out what transaction happened on any database on a given time .
2. who has executed that transaction
3. sql statement of that transaction
0
Comment
Question by:BeyondBGCM
3 Comments
 
LVL 32

Expert Comment

by:ste5an
ID: 39995781
Well, this is a hard task. First of all, I'm not aware of a documentation of the file structure. Then the log does not contain SQL statements. It only shows what happend to the database file(s).

For reading the active log and the SQL statements, you may consider using
-- Read the active log
SELECT	* 
FROM	fn_dblog( null, null );

-- Read from the procedure cache
SELECT	stats.last_execution_time, 
	sqls.[text]
FROM	sys.dm_exec_query_stats stats
	CROSS APPLY sys.dm_exec_sql_text(stats.sql_handle) sqls
ORDER BY stats.last_execution_time;

Open in new window


But what you're describing sounds like an audit. So you may consider using:
* SQL Server Audit (Database Engine)
* Data Collection
* Track Data Changes (SQL Server)
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39995945
I can only concur with above... though it's surely possible, but with lot's of internal (non-public) knowledge of the t-log file structure.
there are tools out there, like for example apex to do the task without having to develop anything:
http://www.apexsql.com/sql_tools_log.aspx
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now