共用方式為


SqlCeException 類別

當基礎提供者從 SQL Server Compact 3.5 資料來源傳回警告或錯誤時,所擲回的例外狀況。這個類別無法被繼承。

命名空間:  System.Data.SqlServerCe
組件:  System.Data.SqlServerCe (在 System.Data.SqlServerCe.dll 中)

語法

'宣告
<SerializableAttribute> _
Public Class SqlCeException _
    Inherits SystemException
'用途
Dim instance As SqlCeException
[SerializableAttribute]
public class SqlCeException : SystemException
[SerializableAttribute]
public ref class SqlCeException : public SystemException
[<SerializableAttribute>]
type SqlCeException =  
    class
        inherit SystemException
    end
public class SqlCeException extends SystemException

備註

每當 .NET Compact Framework Data Provider for SQL Server Compact 3.5 遇到 SQL Server Compact 3.5 引擎中產生的錯誤時,就會建立這個類別 (其他錯誤是以標準 Common Language Runtime 例外狀況來擲回)。SqlCeException 一定會至少包含一個 SqlCeError 執行個體。

範例

下列範例會由於遺漏資料來源而產生 SqlCeException,然後顯示例外狀況。

Dim conn As New SqlCeConnection("Data Source=nonExistingSource.sdf;")

Try
    conn.Open()
Catch e As SqlCeException
    ' Use SqlCeException properties if you need specific
    ' application logic depending on the error condition
    '
    If 25046 = e.NativeError Then 'SSCE_M_FILENOTFOUND
        ' Error specific logic goes here...
        '
    End If

    MessageBox.Show(e.Message)
End Try
SqlCeConnection conn = new SqlCeConnection("Data Source=nonExistingSource.sdf;");

try
{
    conn.Open();
}
catch (SqlCeException e)
{
    // Use SqlCeException properties if you need specific
    // application logic depending on the error condition
    //
    if (25046 == e.NativeError /*SSCE_M_FILENOTFOUND*/)
    {
        // Error specific logic goes here...
        //
    }

    MessageBox.Show(e.Message);
}

繼承階層

System. . :: . .Object
  System. . :: . .Exception
    System. . :: . .SystemException
      System.Data.SqlServerCe..::..SqlCeException
        System.Data.SqlServerCe. . :: . .SqlCeInvalidDatabaseFormatException
        System.Data.SqlServerCe. . :: . .SqlCeLockTimeoutException
        System.Data.SqlServerCe. . :: . .SqlCeTransactionInProgressException

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

請參閱

參考

SqlCeException 成員

System.Data.SqlServerCe 命名空間

SqlCeError

SqlCeErrorCollection