Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » SQL Anywhere 服务器 - 编程 » SQL Anywhere 数据访问 API » SQL Anywhere .NET 数据提供程序

 

跟踪支持

SQL Anywhere .NET 提供程序支持使用 .NET 2.0 或更高版本的跟踪功能进行跟踪。请注意,Windows Mobile 上不支持跟踪。

缺省情况下,跟踪功能被禁用。要启用跟踪功能,请在应用程序的配置文件中指定跟踪源。这里是配置文件的一个示例:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
 <source name="iAnywhere.Data.SQLAnywhere" 
         switchName="SASourceSwitch" 
         switchType="System.Diagnostics.SourceSwitch">
  <listeners>
   <add name="ConsoleListener" 
        type="System.Diagnostics.ConsoleTraceListener"/>
   <add name="EventListener" 
        type="System.Diagnostics.EventLogTraceListener" 
        initializeData="MyEventLog"/>
   <add name="TraceLogListener" 
        type="System.Diagnostics.TextWriterTraceListener" 
        initializeData="myTrace.log" 
        traceOutputOptions="ProcessId, ThreadId, Timestamp"/>
   <remove name="Default"/>
  </listeners>
 </source>
</sources>
<switches>
 <add name="SASourceSwitch" value="All"/>
 <add name="SATraceAllSwitch" value="1" />
 <add name="SATraceExceptionSwitch" value="1" />
 <add name="SATraceFunctionSwitch" value="1" />
 <add name="SATracePoolingSwitch" value="1" />
 <add name="SATracePropertySwitch" value="1" />
</switches>
</system.diagnostics>
</configuration>

跟踪配置信息位于应用程序的 bin\debug 文件夹中,其名称为 app.exe.config

可指定的 traceOutputOptions 包括以下内容:

  • Callstack   编写由 Environment.StackTrace 属性的返回值表示的调用堆栈。

  • DateTime   编写日期和时间。

  • LogicalOperationStack   编写由 CorrelationManager.LogicalOperationStack 属性的返回值表示的逻辑操作堆栈。

  • None   不编写任何元素。

  • ProcessId   编写由 Process.Id 属性的返回值表示的过程标识。

  • ThreadId   编写由当前线程的 Thread.ManagedThreadId 属性的返回值表示的线程标识。

  • Timestamp   编写由 System.Diagnostics.Stopwatch.GetTimeStamp 方法的返回值表示的时间戳。

可通过设置特定的跟踪选项来限制跟踪的内容。缺省情况下,所有的跟踪选项设置均为 0。可设置的跟踪选项包括:

  • SATraceAllSwitch   跟踪全部开关。指定此选项时,会启用所有的跟踪选项。您无需再设置任何其它选项,因为已选择了所有的选项。如果选择此选项,则无法禁用单独的选项。例如,以下语句将不会禁用异常跟踪。
    <add name="SATraceAllSwitch" value="1" />
    <add name="SATraceExceptionSwitch" value="0" />

  • SATraceExceptionSwitch   记录所有异常。跟踪消息具有以下形式。
    <Type|ERR> message='message_text'[ nativeError=error_number]

    仅当具有 SAException 对象时,才会显示 nativeError=error_number 文本。

  • SATraceFunctionSwitch   记录所有进入/退出函数作用域的操作。跟踪消息具有以下形式之一。
    enter_nnn <sa.class_name.method_name|API> [object_id#][parameter_names]
    leave_nnn

    nnn 是一个整数,它表示范围嵌套级别 1、2、3、……可选的 parameter_names 是由空格分隔的参数名列表。

  • SATracePoolingSwitch   记录所有连接池。跟踪消息具有以下形式之一。
    <sa.ConnectionPool.AllocateConnection|CPOOL> connectionString='connection_text'
    <sa.ConnectionPool.RemoveConnection|CPOOL> connectionString='connection_text'
    <sa.ConnectionPool.ReturnConnection|CPOOL> connectionString='connection_text'
    <sa.ConnectionPool.ReuseConnection|CPOOL> connectionString='connection_text'

  • SATracePropertySwitch   记录所有属性设置和检索。跟踪消息具有以下形式之一。
    <sa.class_name.get_property_name|API> object_id#
    <sa.class_name.set_property_name|API> object_id#

您可以使用 TableViewer 示例尝试应用程序跟踪。

♦  配置应用程序以用于跟踪
  1. 必须使用 .NET 2.0 或更高版本。

    启动 Visual Studio,然后打开 samples-dir\SQLAnywhere\ADO.NET\TableViewer 下的 TableViewer 项目文件 (TableViewer.sln)。

  2. 将上面所示配置文件的副本置于应用程序的 bin\debug 文件夹中,并将其命名为 TableViewer.exe.config

  3. 从 [Debug] 菜单中,选择 [Start Debugging]。

应用程序执行完毕后,您会在 samples-dir\SQLAnywhere\ADO.NET\TableViewer\bin\Debug\myTrace.log 中找到一个跟踪输出文件。

Windows Mobile 上不支持跟踪。

有关详细信息,请参见 "Tracing Data Access",网址为 [external link] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/tracingdataaccess.asp