SqlException.Procedure Proprietà

Definizione

Ottiene il nome della stored procedure o della RPC (Remote Procedure Call) che ha generato l'errore.

public:
 property System::String ^ Procedure { System::String ^ get(); };
public string Procedure { get; }
member this.Procedure : string
Public ReadOnly Property Procedure As String

Valore della proprietà

Nome della stored procedure o della RPC.

Esempio

Nell'esempio seguente vengono visualizzati ognuno SqlError all'interno della SqlErrorCollection raccolta.

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

class Program
{
    static void Main()
    {
        string s = GetConnectionString();
        ShowSqlException(s);
        Console.ReadLine();
    }

    public static void ShowSqlException(string connectionString)
    {
        string queryString = "EXECUTE NonExistantStoredProcedure";
        StringBuilder errorMessages = new StringBuilder();

        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            SqlCommand command = new SqlCommand(queryString, connection);
            try
            {
                command.Connection.Open();
                command.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                for (int i = 0; i < ex.Errors.Count; i++)
                {
                    errorMessages.Append("Index #" + i + "\n" +
                        "Message: " + ex.Errors[i].Message + "\n" +
                        "Error Number: " + ex.Errors[i].Number + "\n" +
                        "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                        "Source: " + ex.Errors[i].Source + "\n" +
                        "Procedure: " + ex.Errors[i].Procedure + "\n");
                }
                Console.WriteLine(errorMessages.ToString());
            }
        }
    }

    static private string GetConnectionString()
    {
        // To avoid storing the connection string in your code, 
        // you can retrieve it from a configuration file.
        return "Data Source=(local);Initial Catalog=AdventureWorks;"
            + "Integrated Security=SSPI";
    }
}

Commenti

Si tratta di un wrapper per la Procedure proprietà della prima SqlError nella Errors proprietà.

Se Errors è null, il default valore per string viene restituito.

Si applica a

Vedi anche