Solved

Transaction log and C#

Posted on 2014-04-12
3
1,029 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 34

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 143

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Introduction to Processes

705 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