Export (0) Print
Expand All

SqlError.Server Property

Gets the name of the instance of SQL Server that generated the error.

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public string Server { get; }

Property Value

Type: System.String
The name of the instance of SQL Server.

The following example displays each SqlError within the SqlErrorCollection collection.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft