Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
785 lines (698 sloc) 45.3 KB
<Type Name="SqlException" FullName="System.Data.SqlClient.SqlException">
<TypeSignature Language="C#" Value="public sealed class SqlException : System.Data.Common.DbException" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi serializable sealed beforefieldinit SqlException extends System.Data.Common.DbException" />
<TypeSignature Language="DocId" Value="T:System.Data.SqlClient.SqlException" />
<TypeSignature Language="VB.NET" Value="Public NotInheritable Class SqlException&#xA;Inherits DbException" />
<TypeSignature Language="C++ CLI" Value="public ref class SqlException sealed : System::Data::Common::DbException" />
<TypeSignature Language="F#" Value="type SqlException = class&#xA; inherit DbException" />
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Data.Common.DbException</BaseTypeName>
<BaseTypeName FrameworkAlternate="netframework-1.1">System.SystemException</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0">
<AttributeName>System.Serializable</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0">
<AttributeName>System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>The exception that is thrown when SQL Server returns a warning or error. This class cannot be inherited.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This class is created whenever the .NET Framework Data Provider for SQL Server encounters an error generated from the server. (Client side errors are thrown as standard common language runtime exceptions.) <xref:System.Data.SqlClient.SqlException> always contains at least one instance of <xref:System.Data.SqlClient.SqlError>.
Messages that have a severity level of 10 or less are informational and indicate problems caused by mistakes in information that a user has entered. Severity levels from 11 through 16 are generated by the user, and can be corrected by the user. Severity levels from 17 through 25 indicate software or hardware errors. When a level 17, 18, or 19 error occurs, you can continue working, although you might not be able to execute a particular statement.
The <xref:System.Data.SqlClient.SqlConnection> remains open when the severity level is 19 or less. When the severity level is 20 or greater, the server ordinarily closes the <xref:System.Data.SqlClient.SqlConnection>. However, the user can reopen the connection and continue. In both cases, a <xref:System.Data.SqlClient.SqlException> is generated by the method executing the command.
For information about the warning and informational messages sent by SQL Server, see [Database Engine Events and Errors](/sql/relational-databases/errors-events/database-engine-events-and-errors). The <xref:System.Data.SqlClient.SqlException> class maps to SQL Server severity.
The following is general information on handling exceptions. Your code should catch exceptions to prevent the application from crashing and to allow displaying a relevant error message to the user. You can use database transactions to ensure that the data is consistent regardless of what happens in the client application (including a crash). Features like System.Transaction.TransactionScope or the BeginTransaction method (in System.Data.OleDb.OleDbConnection, System.Data.ODBC.ODBCConnection, and System.Data.SqlClient.SqlConnection) ensure consistent data regardless of exceptions raised by a provider. Transactions can fail, so catch failures and retry the transaction.
Note that beginning with .NET Framework 4.5, <xref:System.Data.SqlClient.SqlException> can return an inner <xref:System.ComponentModel.Win32Exception>.
The exception class of a .NET Framework data provider reports provider-specific errors. For example System.Data.Odbc has OdbcException, System.Data.OleDb has OleDbException, and System.Data.SqlClient has SqlException. For the best level of error detail, catch these exceptions and use the members of these exception classes to get details of the error.
In addition to the provider-specific errors, .NET Framework data provider types can raise .NET Framework exceptions such as System.OutOfMemoryException and System.Threading.ThreadAbortException. Recovery from these exceptions may not be possible.
Bad input can cause a .NET Framework data provider type to raise an exception such as System.ArgumentException or System.IndexOutOfRangeException. Calling a method at the wrong time can raise System.InvalidOperationException.
So, in general, write an exception handler that catches any provider specific exceptions as well as exceptions from the common language runtime. These can be layered as follows:
```csharp
try {
// code here
}
catch (SqlException odbcEx) {
// Handle more specific SqlException exception here.
}
catch (Exception ex) {
// Handle generic ones here.
}
```
Or:
```csharp
try {
// code here
}
catch (Exception ex) {
if (ex is SqlException) {
// Handle more specific SqlException exception here.
}
else {
// Handle generic ones here.
}
}
```
It is also possible for a .NET Framework data provider method call to fail on a thread pool thread with no user code on the stack. In this case, and when using asynchronous method calls, you must register the <xref:System.AppDomain.UnhandledException> event to handle those exceptions and avoid application crash.
## Examples
The following example generates a <xref:System.Data.SqlClient.SqlException> and then displays the exception.
[!code-csharp[Classic WebData SqlException Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlException Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlException Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlException Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="T:System.Data.SqlClient.SqlError" />
<altmember cref="T:System.Data.SqlClient.SqlErrorCollection" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
<Members>
<Member MemberName="Class">
<MemberSignature Language="C#" Value="public byte Class { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance unsigned int8 Class" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.Class" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Class As Byte" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::Byte Class { System::Byte get(); };" />
<MemberSignature Language="F#" Value="member this.Class : byte" Usage="System.Data.SqlClient.SqlException.Class" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Byte</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the severity level of the error returned from the .NET Framework Data Provider for SQL Server.</summary>
<value>A value from 1 to 25 that indicates the severity level of the error.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Messages that have a severity level of 10 or less are informational and indicate problems caused by mistakes in information that a user has entered. Severity levels from 11 through 16 are generated by the user, and can be corrected by the user. Severity levels from 17 through 25 indicate software or hardware errors. When a level 17, 18, or 19 error occurs, you can continue working, although you might not be able to execute a particular statement.
The <xref:System.Data.SqlClient.SqlConnection> remains open when the severity level is 19 or less. When the severity level is 20 or greater, the server ordinarily closes the <xref:System.Data.SqlClient.SqlConnection>. However, the user can reopen the connection and continue. In both cases, a <xref:System.Data.SqlClient.SqlException> is generated by the method executing the command.
For information about the warning and informational messages sent by SQL Server, see the Troubleshooting section of the SQL Server documentation.
This is a wrapper for the <xref:System.Data.SqlClient.SqlError.Class%2A> property of the first <xref:System.Data.SqlClient.SqlError> in the <xref:System.Data.SqlClient.SqlException.Errors%2A> property.
## Examples
The following example displays each <xref:System.Data.SqlClient.SqlError> within the <xref:System.Data.SqlClient.SqlErrorCollection> collection.
[!code-csharp[Classic WebData SqlException.State Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlException.State Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="P:System.Data.SqlClient.SqlException.Number" />
<altmember cref="P:System.Data.SqlClient.SqlException.Source" />
<altmember cref="P:System.Data.SqlClient.SqlException.State" />
<altmember cref="P:System.Data.SqlClient.SqlException.Server" />
<altmember cref="P:System.Data.SqlClient.SqlException.Procedure" />
<altmember cref="P:System.Data.SqlClient.SqlException.LineNumber" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="ClientConnectionId">
<MemberSignature Language="C#" Value="public Guid ClientConnectionId { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Guid ClientConnectionId" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.ClientConnectionId" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property ClientConnectionId As Guid" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property Guid ClientConnectionId { Guid get(); };" />
<MemberSignature Language="F#" Value="member this.ClientConnectionId : Guid" Usage="System.Data.SqlClient.SqlException.ClientConnectionId" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Guid</ReturnType>
</ReturnValue>
<Docs>
<summary>Represents the client connection ID. For more information, see <see href="https://docs.microsoft.com/dotnet/framework/data/adonet/data-tracing">Data Tracing in ADO.NET</see>.</summary>
<value>The client connection ID.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
For a code sample, see <xref:System.Data.SqlClient.SqlException.ToString%2A>.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Errors">
<MemberSignature Language="C#" Value="public System.Data.SqlClient.SqlErrorCollection Errors { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Data.SqlClient.SqlErrorCollection Errors" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.Errors" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Errors As SqlErrorCollection" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::Data::SqlClient::SqlErrorCollection ^ Errors { System::Data::SqlClient::SqlErrorCollection ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Errors : System.Data.SqlClient.SqlErrorCollection" Usage="System.Data.SqlClient.SqlException.Errors" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;xamarinandroid-7.1;xamarinios-10.8;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;xamarinmac-3.0">
<AttributeName>System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Data.SqlClient.SqlErrorCollection</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a collection of one or more <see cref="T:System.Data.SqlClient.SqlError" /> objects that give detailed information about exceptions generated by the .NET Framework Data Provider for SQL Server.</summary>
<value>The collected instances of the <see cref="T:System.Data.SqlClient.SqlError" /> class.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Data.SqlClient.SqlErrorCollection> class always contains at least one instance of the <xref:System.Data.SqlClient.SqlError> class.
This is a wrapper for <xref:System.Data.SqlClient.SqlErrorCollection>. For more information on SQL Server engine errors, see [Database Engine Events and Errors](/sql/relational-databases/errors-events/database-engine-events-and-errors).
## Examples
The following example displays each <xref:System.Data.SqlClient.SqlError> within the <xref:System.Data.SqlClient.SqlErrorCollection> collection.
[!code-csharp[Classic WebData SqlError Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlError Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlError Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlError Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="T:System.Data.SqlClient.SqlErrorCollection" />
<altmember cref="T:System.Data.SqlClient.SqlError" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="GetObjectData">
<MemberSignature Language="C#" Value="public override void GetObjectData (System.Runtime.Serialization.SerializationInfo si, System.Runtime.Serialization.StreamingContext context);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void GetObjectData(class System.Runtime.Serialization.SerializationInfo si, valuetype System.Runtime.Serialization.StreamingContext context) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlException.GetObjectData(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Sub GetObjectData (si As SerializationInfo, context As StreamingContext)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; override void GetObjectData(System::Runtime::Serialization::SerializationInfo ^ si, System::Runtime::Serialization::StreamingContext context);" />
<MemberSignature Language="F#" Value="override this.GetObjectData : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -&gt; unit" Usage="sqlException.GetObjectData (si, context)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="si" Type="System.Runtime.Serialization.SerializationInfo" Index="0" FrameworkAlternate="dotnet-plat-ext-2.1;dotnet-plat-ext-2.2;dotnet-plat-ext-3.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<Parameter Name="context" Type="System.Runtime.Serialization.StreamingContext" Index="1" FrameworkAlternate="dotnet-plat-ext-2.1;dotnet-plat-ext-2.2;dotnet-plat-ext-3.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
</Parameters>
<Docs>
<param name="si">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
<param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param>
<summary>Sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> with information about the exception.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
`GetObjectData` sets a `SerializationInfo` with all the exception object data targeted for serialization. During deserialization, the exception is reconstituted from the `SerializationInfo` transmitted over the stream.
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The <paramref name="si" /> parameter is a null reference (<see langword="Nothing" /> in Visual Basic).</exception>
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="LineNumber">
<MemberSignature Language="C#" Value="public int LineNumber { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance int32 LineNumber" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.LineNumber" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property LineNumber As Integer" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property int LineNumber { int get(); };" />
<MemberSignature Language="F#" Value="member this.LineNumber : int" Usage="System.Data.SqlClient.SqlException.LineNumber" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the line number within the Transact-SQL command batch or stored procedure that generated the error.</summary>
<value>The line number within the Transact-SQL command batch or stored procedure that generated the error.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The line numbering starts at 1; if 0 is returned, the line number is not applicable.
This is a wrapper for the <xref:System.Data.SqlClient.SqlError.LineNumber%2A> property of the first <xref:System.Data.SqlClient.SqlError> in the <xref:System.Data.SqlClient.SqlException.Errors%2A> property.
## Examples
The following example displays each <xref:System.Data.SqlClient.SqlError> within the <xref:System.Data.SqlClient.SqlErrorCollection> collection.
[!code-csharp[Classic WebData SqlException.State Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlException.State Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="P:System.Data.SqlClient.SqlException.Number" />
<altmember cref="P:System.Data.SqlClient.SqlException.Source" />
<altmember cref="P:System.Data.SqlClient.SqlException.State" />
<altmember cref="P:System.Data.SqlClient.SqlException.Class" />
<altmember cref="P:System.Data.SqlClient.SqlException.Server" />
<altmember cref="P:System.Data.SqlClient.SqlException.Procedure" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="Message">
<MemberSignature Language="C#" Value="public override string Message { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Message" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.Message" />
<MemberSignature Language="VB.NET" Value="Public Overrides ReadOnly Property Message As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual property System::String ^ Message { System::String ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Message : string" Usage="System.Data.SqlClient.SqlException.Message" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the text describing the error.</summary>
<value>The text describing the error.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Number">
<MemberSignature Language="C#" Value="public int Number { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance int32 Number" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.Number" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Number As Integer" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property int Number { int get(); };" />
<MemberSignature Language="F#" Value="member this.Number : int" Usage="System.Data.SqlClient.SqlException.Number" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a number that identifies the type of error.</summary>
<value>The number that identifies the type of error.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This is a wrapper for the <xref:System.Data.SqlClient.SqlError.Number%2A> property of the first <xref:System.Data.SqlClient.SqlError> in the <xref:System.Data.SqlClient.SqlException.Errors%2A> property. For more information on SQL Server engine errors, see [Database Engine Events and Errors](/sql/relational-databases/errors-events/database-engine-events-and-errors).
## Examples
The following example displays each <xref:System.Data.SqlClient.SqlError> within the <xref:System.Data.SqlClient.SqlErrorCollection> collection.
[!code-csharp[Classic WebData SqlException.State Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlException.State Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="P:System.Data.SqlClient.SqlException.State" />
<altmember cref="P:System.Data.SqlClient.SqlException.Class" />
<altmember cref="P:System.Data.SqlClient.SqlException.Source" />
<altmember cref="P:System.Data.SqlClient.SqlException.Server" />
<altmember cref="P:System.Data.SqlClient.SqlException.Procedure" />
<altmember cref="P:System.Data.SqlClient.SqlException.LineNumber" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="Procedure">
<MemberSignature Language="C#" Value="public string Procedure { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Procedure" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.Procedure" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Procedure As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::String ^ Procedure { System::String ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Procedure : string" Usage="System.Data.SqlClient.SqlException.Procedure" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the name of the stored procedure or remote procedure call (RPC) that generated the error.</summary>
<value>The name of the stored procedure or RPC.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This is a wrapper for the <xref:System.Data.SqlClient.SqlError.Procedure%2A> property of the first <xref:System.Data.SqlClient.SqlError> in the <xref:System.Data.SqlClient.SqlException.Errors%2A> property.
## Examples
The following example displays each <xref:System.Data.SqlClient.SqlError> within the <xref:System.Data.SqlClient.SqlErrorCollection> collection.
[!code-csharp[Classic WebData SqlException.State Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlException.State Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="P:System.Data.SqlClient.SqlException.Number" />
<altmember cref="P:System.Data.SqlClient.SqlException.State" />
<altmember cref="P:System.Data.SqlClient.SqlException.Class" />
<altmember cref="P:System.Data.SqlClient.SqlException.Server" />
<altmember cref="P:System.Data.SqlClient.SqlException.Source" />
<altmember cref="P:System.Data.SqlClient.SqlException.LineNumber" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="Server">
<MemberSignature Language="C#" Value="public string Server { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Server" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.Server" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Server As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::String ^ Server { System::String ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Server : string" Usage="System.Data.SqlClient.SqlException.Server" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the name of the computer that is running an instance of SQL Server that generated the error.</summary>
<value>The name of the computer running an instance of SQL Server.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This is a wrapper for the <xref:System.Data.SqlClient.SqlError.Server%2A> property of the first <xref:System.Data.SqlClient.SqlError> in the <xref:System.Data.SqlClient.SqlException.Errors%2A> property.
## Examples
The following example displays each <xref:System.Data.SqlClient.SqlError> within the <xref:System.Data.SqlClient.SqlErrorCollection> collection.
[!code-csharp[Classic WebData SqlException.State Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlException.State Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="P:System.Data.SqlClient.SqlException.Number" />
<altmember cref="P:System.Data.SqlClient.SqlException.State" />
<altmember cref="P:System.Data.SqlClient.SqlException.Source" />
<altmember cref="P:System.Data.SqlClient.SqlException.Class" />
<altmember cref="P:System.Data.SqlClient.SqlException.Procedure" />
<altmember cref="P:System.Data.SqlClient.SqlException.LineNumber" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="Source">
<MemberSignature Language="C#" Value="public override string Source { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Source" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.Source" />
<MemberSignature Language="VB.NET" Value="Public Overrides ReadOnly Property Source As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual property System::String ^ Source { System::String ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Source : string" Usage="System.Data.SqlClient.SqlException.Source" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the name of the provider that generated the error.</summary>
<value>The name of the provider that generated the error.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This is a wrapper for the <xref:System.Data.SqlClient.SqlError.Source%2A> property of the first <xref:System.Data.SqlClient.SqlError> in the <xref:System.Data.SqlClient.SqlException.Errors%2A> property.
## Examples
The following example displays each <xref:System.Data.SqlClient.SqlError> within the <xref:System.Data.SqlClient.SqlErrorCollection> collection.
[!code-csharp[Classic WebData SqlException.State Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlException.State Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="P:System.Data.SqlClient.SqlException.Number" />
<altmember cref="P:System.Data.SqlClient.SqlException.State" />
<altmember cref="P:System.Data.SqlClient.SqlException.Class" />
<altmember cref="P:System.Data.SqlClient.SqlException.Server" />
<altmember cref="P:System.Data.SqlClient.SqlException.Procedure" />
<altmember cref="P:System.Data.SqlClient.SqlException.LineNumber" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="State">
<MemberSignature Language="C#" Value="public byte State { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance unsigned int8 State" />
<MemberSignature Language="DocId" Value="P:System.Data.SqlClient.SqlException.State" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property State As Byte" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::Byte State { System::Byte get(); };" />
<MemberSignature Language="F#" Value="member this.State : byte" Usage="System.Data.SqlClient.SqlException.State" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Byte</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a numeric error code from SQL Server that represents an error, warning or "no data found" message. For more information about how to decode these values, see <see href="/sql/relational-databases/errors-events/database-engine-events-and-errors">Database Engine Events and Errors</see>.</summary>
<value>The number representing the error code.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This is a wrapper for the <xref:System.Data.SqlClient.SqlError.State%2A> property of the first <xref:System.Data.SqlClient.SqlError> in the <xref:System.Data.SqlClient.SqlException.Errors%2A> property.
## Examples
The following example displays each <xref:System.Data.SqlClient.SqlError> within the <xref:System.Data.SqlClient.SqlErrorCollection> collection.
[!code-csharp[Classic WebData SqlException.State Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlException.State Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlException.State Example/VB/source.vb#1)]
]]></format>
</remarks>
<altmember cref="P:System.Data.SqlClient.SqlException.Number" />
<altmember cref="P:System.Data.SqlClient.SqlException.Class" />
<altmember cref="P:System.Data.SqlClient.SqlException.Source" />
<altmember cref="P:System.Data.SqlClient.SqlException.Server" />
<altmember cref="P:System.Data.SqlClient.SqlException.Procedure" />
<altmember cref="P:System.Data.SqlClient.SqlException.LineNumber" />
<related type="Article" href="~/docs/framework/data/adonet/ado-net-overview.md">ADO.NET Overview</related>
</Docs>
</Member>
<Member MemberName="ToString">
<MemberSignature Language="C#" Value="public override string ToString ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance string ToString() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.SqlClient.SqlException.ToString" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function ToString () As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; override System::String ^ ToString();" />
<MemberSignature Language="F#" Value="override this.ToString : unit -&gt; string" Usage="sqlException.ToString " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.SqlClient</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.4.0.0</AssemblyVersion>
<AssemblyVersion>4.5.0.0</AssemblyVersion>
<AssemblyVersion>4.6.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a string that represents the current <see cref="T:System.Data.SqlClient.SqlException" /> object, and includes the client connection ID (for more information, see <see cref="P:System.Data.SqlClient.SqlException.ClientConnectionId" />).</summary>
<returns>A string that represents the current <see cref="T:System.Data.SqlClient.SqlException" /> object.<see cref="T:System.String" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Examples
The following C# example shows how a connection attempt to a valid server but non-existent database causes a <xref:System.Data.SqlClient.SqlException>, which includes the client connection ID:
```csharp
using System.Data.SqlClient;
using System;
public class A {
public static void Main() {
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Data Source=a_valid_server;Initial Catalog=Northwinda;Integrated Security=true";
try {
connection.Open();
}
catch (SqlException p) {
Console.WriteLine("{0}", p.ClientConnectionId);
Console.WriteLine("{0}", p.ToString());
}
connection.Close();
}
}
```
The following Visual Basic sample is functionally equivalent to the previous (C#) sample:
```vb
Imports System.Data.SqlClient
Imports System
Module Module1
Sub Main()
Dim connection As New SqlConnection()
connection.ConnectionString = "Data Source=a_valid_server;Initial Catalog=Northwinda;Integrated Security=true"
Try
connection.Open()
Catch p As SqlException
Console.WriteLine("{0}", p.ClientConnectionId)
Console.WriteLine("{0}", p.ToString())
End Try
connection.Close()
End Sub
End Module
```
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>
You can’t perform that action at this time.