• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1159
  • Last Modified:

Transaction log and C#

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
BeyondBGCM
Asked:
BeyondBGCM
1 Solution
 
ste5anSenior DeveloperCommented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now