Tracing IBM Data Server Provider for .NET

You can trace the activity of the IBM Data Server Provider for .NET by setting environment variables or by using an application configuration file.

About this task

You generate the .NET application trace by using the System.Diagnostics.Trace class. You can control the tracing of the .NET public methods and properties by using the System.Diagnostics.TraceSwitch class without recompiling or modifying the source code. Only the method and property calls that are explicitly made by the applications are traced. Internal method and property calls that are made by a .NET provider are not traced.

The DB2NMPTRACE trace switch property and the DB2NMPTRACE environment variable initializes the System.Diagnostics.TraceSwitch class for the Db2® .NET provider.

The IFXNMPTRACE trace switch property and the IFXNMPTRACE environment variable initializes the System.Diagnostics.TraceSwitch class for the Informix® .NET provider.
Important: The Informix .NET provider (IBM.Data.Informix.dll) is deprecated and might be discontinued in a later release. Start using the Db2 .NET provider (IBM.Data.Db2.dll) to connect to Informix database servers.
You can specify different levels of tracing by specifying one of the following System.Diagnostics.TraceLevel enumeration values for the System.Diagnostics.TraceSwitch class:
0
Turns off the tracing.
1
Turns on the tracing for errors.
2
Turns on the tracing for errors and warnings.
3
Turns on the tracing for errors, warnings, and informational messages.
4
Turns on the tracing for all messages.

Procedure

To trace IBM Data Server Provider for .NET:

  1. Determine which .NET provider your application is using by checking the source code or contacting your application vendor.
    If your application references the IBM.Data.DB2 namespace, the application is using the Db2 .NET provider. If your application references the IBM.Data.Informix namespace, the application is using the Informix .NET provider.
  2. Enable the .NET provider trace:
    • For applications that use the IBM.Data.DB2 namespace, use one of the following methods:
      • Set environment variables in the same session as the .NET application that you are tracing:
        1. Set the DB2NMPTRACE environment variable to a System.Diagnostics.TraceLevel enumeration value by using the set command. You can specify a value of 0 -4, as explained in the "About this task" section. An example follows:
          set DB2NMPTRACE=1
        2. Specify the trace output directory by setting the DB2NMPCONSOLE environment variable with the set command. An example follows.
          set DB2NMPCONSOLE=c:\tmp\nmptrace
          The directory must exist, and you must have write permission for it.
      • In the application configuration file, set the DB2NMPTRACE switch name element to a System.Diagnostics.TraceLevel enumeration value of 0 -4. An example follows:
        <system.diagnostics>
          <trace autoflush="false" indentsize="4">
            <listeners>
              <add name="configConsoleListener" type="System.Diagnostics.ConsoleTraceListener" /> 
            </listeners>      
          </trace>
          <switches>
            <add name="DB2NMPTRACE" value="1" />
          </switches>
        </system.diagnostics>
        The trace that you take by using the application configuration file is logged to a console.
    • For applications that use the IBM.Data.Informix namespace, use one of the following two methods:
      • Set the environment variables in the same session as the .NET application that you are tracing:
        1. Set the IFXNMPTRACE environment variable to a System.Diagnostics.TraceLevel enumeration value by using the set command. You can specify a value of 0 -4, as explained in the "About this task" section. An example follows:
          set IFXNMPTRACE=1
        2. Specify the trace output directory by specifying the IFXNMPCONSOLE environment variable with the set command. An example follows:
          set IFXNMPCONSOLE=c:\tmp\nmptrace
          The directory must exist, and you must have write permission for it.
      • In the application configuration file, set the IFXNMPTRACE switch name element to a System.Diagnostics.TraceLevel enumeration value of 0 - 4. An example follows:
        <system.diagnostics>
          <trace autoflush="false" indentsize="4">
            <listeners>
              <add name="configConsoleListener" type="System.Diagnostics.ConsoleTraceListener" /> 
            </listeners>      
          </trace>
          <switches>
            <add name="IFXNMPTRACE" value="1" /> 
          </switches>
        </system.diagnostics>
        The trace that you take by using the application configuration file is logged to a console.

Results

An example of trace output follows:
* * Started tracing program
* Creating connection
DB2Connection.DB2Connection1 api entry - database=nmpfvtu;
DB2Connection.DB2Connection1 api exit, rc = 0
* Opening connection
DB2Connection.Open api entry
DB2Connection.Open api exit, rc = 0
* Closing connection
DB2Connection.Close api entry
DB2Connection.Close api exit, rc = 0
* Ending program
DB2Connection.~DB2Connection api entry
DB2Connection.~DB2Connection api exit, rc = 0
DB2Connection.Dispose api entry
DB2Connection.Dispose api exit, rc = 0
The trace points that are dumped by the application are prefixed with an asterisk (*).