SqlError.LineNumber Property
Definition
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 the line number within the Transact-SQL command batch or stored procedure that contains the error.
public:
property int LineNumber { int get(); };
public int LineNumber { get; }
member this.LineNumber : int
Public ReadOnly Property LineNumber As Integer
Property Value
The line number within the Transact-SQL command batch or stored procedure that contains the error.
Examples
The following example displays each SqlError within the SqlErrorCollection collection.
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();
}
}
}
Remarks
Line numbering starts at 1. If the value is 0, the line number is not applicable.
For more information on errors generated by SQL Server, see Database Engine Events and Errors.