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

SQL Anywhere 12.0.0 (中文) » UltraLite - .NET 编程 » 了解 UltraLite.NET 开发

 

处理错误

您可以使用标准的 .NET 错误处理功能来处理错误。大多数 UltraLite 方法都会抛出 ULException 错误。可以使用 ULException.NativeError 来检索指派给此错误的 ULSQLCode 值。ULException 具有 Message 属性,使用该属性可以获取错误的描述性文本。ULSQLCode 错误是表示错误类型的负数。

有关错误代码的列表,请参见错误消息

同步之后,可以使用连接的 SyncResult 属性来获取更详细的错误信息。例如,以下示例说明了用于报告在同步过程中发生的错误的可行方法:



public void Sync()
  {
         try
         {
            _conn.Synchronize( this );
            _inSync = false;
         } 
         catch( ULException uEx ){
            if( uEx.NativeError == ULSQLCode.SQLE_COMMUNICATIONS_ERROR )
            {
               MessageBox.Show(
                    "StreamErrorCode = " + 
                     _conn.SyncResult.StreamErrorCode.ToString() + 
                     "\r\n"
                  + "StreamErrorContext = " + 
                    _conn.SyncResult.StreamErrorContext + "\r\n"
                  + "StreamErrorID = " + 
                    _conn.SyncResult.StreamErrorID + "\r\n"
                  + "StreamErrorSystem = " + 
                    _conn.SyncResult.StreamErrorSystem + "\r\n"
                  );
            }
            else
            {
               MessageBox.Show(uEx.Message);
            }
         }
         catch(System.Exception ex )
         {
            MessageBox.Show(ex.Message);
         }
  }
 另请参见