The exception that is thrown when the underlying provider returns a warning or error from a SQL Server CE data source. This class cannot be inherited.
For a list of all members of this type, see SqlCeException Members.
System.Object
System.Exception
System.SystemException
System.Data.SqlServerCe.SqlCeException
[Visual Basic] NotInheritable Public Class SqlCeException Inherits SystemException [C#] public sealed class SqlCeException : SystemException [C++] public __gc __sealed class SqlCeException : public SystemException [JScript] public class SqlCeException extends SystemException
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
This class is created whenever the .NET Compact Framework Data Provider for SQL Server CE encounters an error generated from within the SQL Server CE Engine. (Other errors are thrown as standard common language runtime exceptions.) SqlCeException always contains at least one instance of SqlCeError.
[Visual Basic, C#] The following example generates an SqlCeException due to a missing data source, and then displays the exception.
[Visual Basic] Public Sub ShowSqlCeException() Dim mySelectQuery As String = "SELECT column1 FROM table1" Dim myConnection As New SqlCeConnection("Data Source=nonExistSource.sdf;") Dim myCommand As New SqlCeCommand(mySelectQuery, myConnection) Try myCommand.Connection.Open() Catch e As SqlCeException Dim errorCollection As SqlCeErrorCollection = e.Errors Dim bld As New StringBuilder() Dim inner As Exception = e.InnerException If Not inner is Nothing Then MessageBox.Show(("Inner Exception: " & inner.ToString())) End If Dim err As SqlCeError For Each err In errorCollection bld.Append((ControlChars.Cr & " Error Code: " & err.HResult.ToString("X"))) bld.Append((ControlChars.Cr & " Message : " & err.Message)) bld.Append((ControlChars.Cr & " Minor Err.: " & err.NativeError)) bld.Append((ControlChars.Cr & " Source : " & err.Source)) Dim numPar As Integer For Each numPar In err.NumericErrorParameters If 0 <> numPar Then bld.Append((ControlChars.Cr & " Num. Par. : " & numPar)) End If Next numPar Dim errPar As String For Each errPar In err.ErrorParameters If [String].Empty <> errPar Then bld.Append((ControlChars.Cr & " Err. Par. : " & errPar)) End If Next errPar MessageBox.Show(bld.ToString()) bld.Remove(0, bld.Length) Next err End Try End Sub 'ShowSqlCeException [C#] public void ShowSqlCeException() { string mySelectQuery = "SELECT column1 FROM table1"; SqlCeConnection myConnection = new SqlCeConnection("Data Source=nonExistSource.sdf;"); SqlCeCommand myCommand = new SqlCeCommand(mySelectQuery,myConnection); try { myCommand.Connection.Open(); } catch (SqlCeException e) { SqlCeErrorCollection errorCollection = e.Errors; StringBuilder bld = new StringBuilder(); Exception inner = e.InnerException; if (null != inner) { MessageBox.Show("Inner Exception: " + inner.ToString()); } foreach (SqlCeError err in errorCollection) { bld.Append("\n Error Code: " + err.HResult.ToString("X")); bld.Append("\n Message : " + err.Message); bld.Append("\n Minor Err.: " + err.NativeError); bld.Append("\n Source : " + err.Source); foreach (int numPar in err.NumericErrorParameters) { if (0 != numPar) bld.Append("\n Num. Par. : " + numPar); } foreach (string errPar in err.ErrorParameters) { if (String.Empty != errPar) bld.Append("\n Err. Par. : " + errPar); } MessageBox.Show(bld.ToString()); bld.Remove(0, bld.Length); } } }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.Data.SqlServerCe
Platforms: .NET Compact Framework - Windows CE .NET
Assembly: System.Data.Sqlserverce (in System.Data.Sqlserverce.dll)
SqlCeException Members | System.Data.SqlServerCe Namespace | SqlCeError | SqlCeErrorCollection