LinqConnect Documentation
In This Topic
    LinqMonitor
    In This Topic
    LinqMonitor
    LinqConnect Documentation
    LinqMonitor
    [email protected]

    Special component LinqMonitor is used for monitoring of the application interaction with database. It allows you to print trace messages to any output stream and use the dbMonitor tool for trace viewing. LinqMonitor offers you a possibility to monitor your database operations from DataContext. It can be used for any kind of applications – desktop, ASP.NET and windows services.

    To start monitoring do the following steps:

    The following example shows you how to use LinqMonitor:

    static void Main(string[] args)
    {
         LinqMonitor linqMonitor = new LinqMonitor();
         linqMonitor.IsActive = true;
                
         CrmDemoContext.CrmDemoDataContext db = new CrmDemoContext.CrmDemoDataContext();
         linqMonitor.TraceEvent += new Devart.Data.Linq.Monitoring.MonitorEventHandler(OnEvent);
         var query = from it in db.Companies
                     select it;
                
         foreach (CrmDemoContext.Company company in query)
         {
             Console.WriteLine(company.CompanyName);
         }
     
         linqMonitor.TraceEvent -= OnEvent; 
    }
    
    static void OnEvent(object sender, MonitorEventArgs e)
    {
         if (e.TracePoint == MonitorTracePoint.BeforeEvent)
         {
             Console.WriteLine("Description: " + e.Description);
             Console.WriteLine("Extra info: " + e.ExtraInfo);
         }
    } 
    

    
    Private Shared Sub Main(ByVal args As String())   
        Dim linqMonitor As New LinqMonitor
        linqMonitor.IsActive = True
        
        Dim db As New CrmDemoDataContext
        AddHandler linqMonitor.TraceEvent, New MonitorEventHandler(AddressOf Program.OnEvent)
        
        Dim query = From it in db.Companies
                    Select it;
        
        Dim company As Company
        For Each company In query
            Console.WriteLine(company.CompanyName)
        Next
        
        RemoveHandler linqMonitor.TraceEvent, New MonitorEventHandler(AddressOf Program.OnEvent)
    End Sub
    
    Private Shared Sub OnEvent(ByVal sender As Object, ByVal e As MonitorEventArgs)
        If (e.TracePoint = MonitorTracePoint.BeforeEvent) Then
            Console.WriteLine(("Description: " & e.Description))
            Console.WriteLine(("Extra info: " & e.ExtraInfo))
        End If
    End Sub
    
    

    The output of this sample is listed below:

    Description: Open connection: "User ID=CRM_DEMO;Password=CRM_DEMO;SERVER=DB;"
    
    Extra info: User ID=CRM_DEMO;Password=CRM_DEMO;SERVER=DB;;
    Description: Execute: SELECT t1."CompanyID", t1."CompanyName", t1."PrimaryContact", t1."Web", t1."Email", t1."AddressTitle", t1."Address", t1."City", t1."Region", t1."PostalCode", t1."Country", t1."Phone", t1."Fax" FROM CRM_DEMO."Company" t1
    Extra info: -1
    Borland UK CodeGear Division Alpha Bank ... Orderbase Consulting Gmbh
    Description: Disconnect
    Extra info:

    Monitoring capabilities are available at design-time as well. Just change the IsActive property to true and add a new handler on the Properties window.

    NoteNote:

    Please note that the LinqMonitor doesn't support connection pool monitoring. To monitor connection pools install the Professional editions of the Devart data providers and use provider-specific monitors (OracleMonitor, MySqlMonitor, PgSqlMonitor, SQLiteMonitor).