Dela via


SqlError.Number Property

Definition

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

Property Value

The number that identifies the type of error.

Examples

The following example displays each SqlError within the SqlErrorCollection collection.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Data.SqlClient;

namespace Classic_WebData_SqlError.StateCS
{
    class Program
    {
        static void Main()
        {
            //DisplaySqlErrors();
        }

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

Remarks

The following table describes the possible values for this property:

Source of ErrorSqlError.NumberSqlError.StateSqlException 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 0No
Connection timeout-20Yes (Number = 258)
Communication error (non-LocalDB)Win32 error code0Yes (Number = Win32 error code)
Communication error (LocalDB)Win32 error code0No
Encryption capability mismatch200No
Failed to start LocalDBWin32 error code0No
Read-only routing failure00No
Server had severe error processing query00No
Processed cancellation while parsing results00No
Failed to create user instance00No

For more information on errors generated by SQL Server, see Database Engine Events and Errors.

Applies to