Aracılığıyla paylaş


SqlError.State Özellik

Tanım

Bazı hata iletileri, Veritabanı Altyapısı için kodun birden çok noktasında oluşturulabilir. Örneğin, birkaç farklı koşul için 1105 hatası oluşturulabilir. Hata oluşturan her belirli koşul benzersiz bir durum kodu atar.

public:
 property System::Byte State { System::Byte get(); };
public byte State { get; }
member this.State : byte
Public ReadOnly Property State As Byte

Özellik Değeri

Eyalet kodu.

Örnekler

Aşağıdaki örnek koleksiyondaki her SqlError birini SqlErrorCollection görüntüler.

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

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

Açıklamalar

Durum yalnızca sunucudan alınan hatalar için ayarlanır.

SQL Server tarafından oluşturulan hatalar hakkında daha fazla bilgi için bkz. Veritabanı Altyapısı Hatalarını Anlama.

Şunlara uygulanır