SqlCeException Class

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

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class SqlCeException
    Inherits SystemException
[SerializableAttribute] 
public class SqlCeException : SystemException
[SerializableAttribute] 
public ref class SqlCeException : public SystemException
/** @attribute SerializableAttribute() */ 
public class SqlCeException extends SystemException
SerializableAttribute 
public class SqlCeException extends SystemException

Remarks

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

Inheritance Hierarchy

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

Example

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.

Platforms

Development Platforms

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0

See Also

Reference

SqlCeException Members
System.Data.SqlServerCe Namespace
SqlCeError Class
SqlCeErrorCollection Class