SqlError.Number Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a number that identifies the type of error.
public:
property int Number { int get(); };
public int Number { get; }
member this.Number : int
Public ReadOnly Property Number As Integer
The number that identifies the type of error.
The following example displays each SqlError within the SqlErrorCollection collection.
public void DisplaySqlErrors(SqlException exception)
{
for (int i = 0; i < exception.Errors.Count; i++)
{
Console.WriteLine("Index #" + i + "\n" +
"Source: " + exception.Errors[i].Source + "\n" +
"Number: " + exception.Errors[i].Number.ToString() + "\n" +
"State: " + exception.Errors[i].State.ToString() + "\n" +
"Class: " + exception.Errors[i].Class.ToString() + "\n" +
"Server: " + exception.Errors[i].Server + "\n" +
"Message: " + exception.Errors[i].Message + "\n" +
"Procedure: " + exception.Errors[i].Procedure + "\n" +
"LineNumber: " + exception.Errors[i].LineNumber.ToString());
}
Console.ReadLine();
}
Public Sub DisplaySqlErrors(ByVal exception As SqlException)
Dim i As Integer
For i = 0 To exception.Errors.Count - 1
Console.WriteLine(("Index #" & i & ControlChars.NewLine & _
"Source: " & exception.Errors(i).Source & ControlChars.NewLine & _
"Number: " & exception.Errors(i).Number.ToString() & ControlChars.NewLine & _
"State: " & exception.Errors(i).State.ToString() & ControlChars.NewLine & _
"Class: " & exception.Errors(i).Class.ToString() & ControlChars.NewLine & _
"Server: " & exception.Errors(i).Server & ControlChars.NewLine & _
"Message: " & exception.Errors(i).Message & ControlChars.NewLine & _
"Procedure: " & exception.Errors(i).Procedure & ControlChars.NewLine & _
"LineNumber: " & exception.Errors(i).LineNumber.ToString()))
Next i
Console.ReadLine()
End Sub
The following table describes the possible values for this property:
Source of Error | SqlError.Number | SqlError.State | SqlException has inner Win32Exception (beginning with.NET Framework 4.5) |
---|---|---|---|
Error from server | Server error code This number corresponds to an entry in the master.dbo.sysmessages table. |
Typically greater than 0 | No |
Connection timeout | -2 | 0 | Yes (Number = 258) |
Communication error (non-LocalDB) | Win32 error code | 0 | Yes (Number = Win32 error code) |
Communication error (LocalDB) | Win32 error code | 0 | No |
Encryption capability mismatch | 20 | 0 | No |
Failed to start LocalDB | Win32 error code | 0 | No |
Read-only routing failure | 0 | 0 | No |
Server had severe error processing query | 0 | 0 | No |
Processed cancellation while parsing results | 0 | 0 | No |
Failed to create user instance | 0 | 0 | No |
For more information on errors generated by SQL Server, see Database Engine Events and Errors.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, 6 (package-provided), 8 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
.NET feedback
.NET is an open source project. Select a link to provide feedback: