Solved

Transaction log and C#

Posted on 2014-04-12
3
997 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 33

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

734 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