CommandText: executed statement

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for universal data access
Post Reply
mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

CommandText: executed statement

Post by mlagasio » Mon 06 Jun 2011 09:50

Hi

is there access to read from UniCommand the statement effectively executed agaist a data provider (what I assign to CommandText may has some characters specific to UniSQL)? I could use these "true" statements in log messages.

Thank you

Best Regard

Marco Lagasio

Shalex
Site Admin
Posts: 8239
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Tue 07 Jun 2011 06:21

Please use the dbMonitor tool that performs per-component tracing of database events such as commit, rollback, SQL statement execute etc.
Download link: https://www.devart.com/dbmonitor/dbmonitor.exe
Documentation: https://www.devart.com/dotconnect/unive ... nitor.html

mlagasio
Posts: 43
Joined: Mon 14 Mar 2011 13:42

Post by mlagasio » Mon 13 Jun 2011 09:31

Hi,

I think use of dbMonitor only in a debug context. I need to log statement error in a release context. That is I execute a statement. If it's all ok then I go to next instruction. If data source raise an exception then, in a catch block I insert a row in a log table with the sql statement that generates the exception. Following your hint I need to create and activate the instance of dbMonitor before to execute the statement, anyway (also if the execution don't raise exceptions)?

Marco

Shalex
Site Admin
Posts: 8239
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Thu 16 Jun 2011 11:46

Please try handling the UniMonitor.TraceEvent event to create a log manually.

Code: Select all

    class Program {
        static MonitorEventArgs previousArgs;
        static void OnEvent(object sender, MonitorEventArgs e) {
            if (e.EventType == MonitorEventType.Error) {
                Console.WriteLine("Description of error: " + e.Description);
                Console.WriteLine("Extra info  of error:  " + e.ExtraInfo);
                if (previousArgs != null){
                    Console.WriteLine("  Description of activity that caused error: " + previousArgs.Description);
                    Console.WriteLine("  Extra info  of activity that caused error: " + previousArgs.ExtraInfo);
                }
            }
            if (e.TracePoint == MonitorTracePoint.BeforeEvent) {
                previousArgs = e;
            }
        }


        [MTAThread]
        static void Main(string[] args) {
            UniConnection myConn = new UniConnection("Provider=Oracle;Direct=true;host=dboracle;SID=orcl1120;uid=***;pwd=***;");
            UniMonitor myMonitor = new UniMonitor();
            myMonitor.TraceEvent += new MonitorEventHandler(OnEvent);
            myMonitor.IsActive = true;
            UniCommand myCommand = new UniCommand("select count(*) from dept", myConn);
            try {
                myConn.Open();
                Console.WriteLine(myCommand.ExecuteScalar());
            }
            catch (UniException ex) {
                Console.WriteLine("Exception occured. See log for details.");
            }
            myConn.Close();
            myMonitor.TraceEvent -= new MonitorEventHandler(OnEvent);
            Console.ReadLine();
        } 
    }

Post Reply