次の方法で共有


SqlError.State プロパティ

定義

いくつかのエラー メッセージは、データベース エンジンのコードの複数のポイントで表示できます。 たとえば、複数の異なる条件に対して 1105 エラーが生成されることがあります。 エラーを生成する特定の条件はそれぞれ一意の状態コードを割り当てます。

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

プロパティ値

状態コード。

次の例では、コレクション内の各 をSqlErrorSqlErrorCollection表示します。

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

注釈

状態は、サーバーから受信したエラーに対してのみ設定されます。

SQL Serverによって生成されるエラーの詳細については、「データベース エンジン エラーについて」を参照してください。

適用対象