Page 1 of 1
CommandText: executed statement
Posted: Mon 06 Jun 2011 09:50
by mlagasio
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
Posted: Tue 07 Jun 2011 06:21
by Shalex
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
Posted: Mon 13 Jun 2011 09:31
by mlagasio
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
Posted: Thu 16 Jun 2011 11:46
by Shalex
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();
}
}