Sdílet prostřednictvím


SqlCeException Class

The exception thrown when the underlying provider returns a warning or error from a SQL Server Compact data source. This class cannot be inherited.

Inheritance Hierarchy

System.Object
  System.Exception
    System.SystemException
      System.Runtime.InteropServices.ExternalException
        System.Data.Common.DbException
          System.Data.SqlServerCe.SqlCeException
            System.Data.SqlServerCe.SqlCeInvalidDatabaseFormatException
            System.Data.SqlServerCe.SqlCeLockTimeoutException
            System.Data.SqlServerCe.SqlCeTransactionInProgressException

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class SqlCeException _
    Inherits DbException
'Usage
Dim instance As SqlCeException
[SerializableAttribute]
public class SqlCeException : DbException
[SerializableAttribute]
public ref class SqlCeException : public DbException
[<SerializableAttribute>]
type SqlCeException =  
    class
        inherit DbException
    end
public class SqlCeException extends DbException

The SqlCeException type exposes the following members.

Constructors

  Name Description
Protected method SqlCeException Constructor that helps in serialization.

Top

Properties

  Name Description
Public property Data (inherited from Exception)
Public property ErrorCode (inherited from ExternalException)
Public property Errors Gets a collection of one or more SqlCeError objects that contain detailed information about exceptions generated by the .NET Compact Framework Data Provider for SQL Server Compact.
Public property HelpLink (inherited from Exception)
Public property HResult Gets the HRESULT value of the exception. This value is the same as the value of HResult for the first instance of SqlCeError in the SqlCeErrorCollection for the exception.
Public property InnerException (inherited from Exception)
Public property Message Gets the text describing the first instance of SqlCeError in the SqlCeErrorCollection for this exception. (Overrides Exception.Message.)
Public property NativeError Gets the native error number of the first SqlCeError in the SqlCeErrorCollection. For more information about the error, see the "SQL Server Compact Errors" topic in the Troubleshooting section of SQL Server Compact Books Online.
Public property Source Gets the name of the OLE DB provider that generated the error. (Overrides Exception.Source.)
Public property StackTrace (inherited from Exception)
Public property TargetSite (inherited from Exception)

Top

Methods

  Name Description
Public method Equals (inherited from Object)
Protected method Finalize (inherited from Object)
Public method GetBaseException (inherited from Exception)
Public method GetHashCode (inherited from Object)
Public method GetObjectData Security Critical. Populates a SerializationInfo with the data required to serialize the object. (Overrides Exception.GetObjectData(SerializationInfo, StreamingContext).)
Public method GetType (inherited from Exception)
Protected method MemberwiseClone (inherited from Object)
Public method ToString (inherited from Exception)

Top

Remarks

This class is created whenever the .NET Compact Framework Data Provider for SQL Server Compact encounters an error generated from within the SQL Server Compact Engine. (Other errors are thrown as standard common language runtime exceptions.) SqlCeException always contains at least one instance of SqlCeError.

Examples

The following example generates a SqlCeException due to a missing data source, and then displays the exception.

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);
}

Thread Safety

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.

See Also

Reference

System.Data.SqlServerCe Namespace

SqlCeError

SqlCeErrorCollection