Solved

Transaction log and C#

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

809 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