• How to read transaction log file of SQL server in C#

    Abhey Member

    How to read transaction log file of SQL server in C#

  • ShikhaTan Member

    To read transaction log file of SQL server in C# 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 happened 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;
    
  • Abhey Member

    It’s 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: You may consider using:

    http://www.apexsql.com/sql_tools_log.aspx
    http://msdn.microsoft.com/en-us/library/cc280386%28v=sql.110%29.aspx
    http://technet.microsoft.com/en-us/library/bb677179.aspx
    http://msdn.microsoft.com/en-us/library/bb933994.aspx
    
Viewing 2 reply threads
  • You must be logged in to reply to this topic.