This documentation is archived and is not being maintained.

SqlErrorCollection Class

Collects all errors generated by the .NET Framework Data Provider for SQL Server. This class cannot be inherited.

For a list of all members of this type, see SqlErrorCollection Members.


[Visual Basic]
NotInheritable Public Class SqlErrorCollection
   Implements ICollection, IEnumerable
public sealed class SqlErrorCollection : ICollection, IEnumerable
public __gc __sealed class SqlErrorCollection : public
   ICollection, IEnumerable
class SqlErrorCollection implements ICollection, IEnumerable

Thread Safety

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


This class is created by SqlException to collect instances of the SqlError class. SqlErrorCollection always contains at least one instance of the SqlError class.


[Visual Basic, C#, C++] The following example displays each SqlError within the SqlErrorCollection collection.

[Visual Basic] 
Public Sub DisplaySqlErrors(myException As SqlException)
    Dim i As Integer
    For i = 0 To myException.Errors.Count - 1
        MessageBox.Show("Index #" & i & ControlChars.NewLine & _
                        "Error: " & myException.Errors(i).ToString() & ControlChars.NewLine)
    Next i
End Sub 'DisplaySqlErrors

public void DisplaySqlErrors(SqlException myException) 
    for (int i=0; i < myException.Errors.Count; i++)
       MessageBox.Show("Index #" + i + "\n" +
            "Error: " + myException.Errors[i].ToString() + "\n");

void DisplaySqlErrors(SqlException* myException) 
    for (int i=0; i < myException->Errors->Count; i++)
       MessageBox::Show(String::Format( S"Index #{0}\nError: {1}\n",
          __box(i), myException->Errors->Item[i] ));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Data.SqlClient

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

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

See Also

SqlErrorCollection Members | System.Data.SqlClient Namespace | SqlError | SqlException