Skip to content

Commit b2dfc95

Browse files
rojicarlossanlop
authored andcommitted
Correct timeout remarks for SqlClient async command methods (#3343)
1 parent 7f1e86f commit b2dfc95

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

xml/System.Data.SqlClient/SqlCommand.xml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,13 @@ class Program {
759759
<format type="text/markdown"><![CDATA[
760760
761761
## Remarks
762-
The <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method starts the process of asynchronously executing a [!INCLUDE[tsql](~/includes/tsql-md.md)] statement or stored procedure that does not return rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method to finish the operation. The <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method returns immediately (<xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> has no effect on <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A>), but until the code executes the corresponding <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same <xref:System.Data.SqlClient.SqlCommand> object. Calling the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> before the command's execution is completed causes the <xref:System.Data.SqlClient.SqlCommand> object to block until the execution is finished.
762+
The <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method starts the process of asynchronously executing a [!INCLUDE[tsql](~/includes/tsql-md.md)] statement or stored procedure that does not return rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method to finish the operation. The <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method returns immediately, but until the code executes the corresponding <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same <xref:System.Data.SqlClient.SqlCommand> object. Calling the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> before the command's execution is completed causes the <xref:System.Data.SqlClient.SqlCommand> object to block until the execution is finished.
763763
764764
Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous.
765765
766766
Because this overload does not support a callback procedure, developers must either poll to determine whether the command has completed, using the <xref:System.IAsyncResult.IsCompleted%2A> property of the <xref:System.IAsyncResult> returned by the <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method; or wait for the completion of one or more commands using the <xref:System.IAsyncResult.AsyncWaitHandle%2A> property of the returned <xref:System.IAsyncResult>.
767+
768+
This method ignores the <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property.
767769
768770
769771
@@ -837,7 +839,7 @@ The <see cref="T:System.Data.SqlClient.SqlConnection" /> closed or dropped durin
837839
<format type="text/markdown"><![CDATA[
838840
839841
## Remarks
840-
The <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that does not return rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method to finish the operation. The <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method returns immediately (<xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> has no effect on <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A>), but until the code executes the corresponding <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same <xref:System.Data.SqlClient.SqlCommand> object. Calling the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> before the command's execution is completed causes the <xref:System.Data.SqlClient.SqlCommand> object to block until the execution is finished.
842+
The <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that does not return rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method to finish the operation. The <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method returns immediately, but until the code executes the corresponding <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same <xref:System.Data.SqlClient.SqlCommand> object. Calling the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> before the command's execution is completed causes the <xref:System.Data.SqlClient.SqlCommand> object to block until the execution is finished.
841843
842844
The `callback` parameter lets you specify an <xref:System.AsyncCallback> delegate that is called when the statement has completed. You can call the <xref:System.Data.SqlClient.SqlCommand.EndExecuteNonQuery%2A> method from within this delegate procedure, or from any other location within your application. In addition, you can pass any object in the `asyncStateObject` parameter, and your callback procedure can retrieve this information using the <xref:System.IAsyncResult.AsyncState%2A> property.
843845
@@ -846,6 +848,8 @@ The <see cref="T:System.Data.SqlClient.SqlConnection" /> closed or dropped durin
846848
Because the callback procedure executes from within a background thread supplied by the Microsoft .NET common language runtime, it is very important that you take a rigorous approach to handling cross-thread interactions from within your applications. For example, you must not interact with a form's contents from within your callback procedure; should you have to update the form, you must switch back to the form's thread in order to do your work. The example in this topic demonstrates this behavior.
847849
848850
All errors that occur during the execution of the operation are thrown as exceptions in the callback procedure. You must handle the exception in the callback procedure, not in the main application. See the example in this topic for additional information on handling exceptions in the callback procedure.
851+
852+
This method ignores the <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property.
849853
850854
851855
@@ -934,6 +938,8 @@ A <see cref="P:System.Data.SqlClient.SqlParameter.SqlDbType" /> other than **Xml
934938
Because this overload does not support a callback procedure, developers must either poll to determine whether the command has completed, using the <xref:System.IAsyncResult.IsCompleted%2A> property of the <xref:System.IAsyncResult> returned by the <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A> method; or wait for the completion of one or more commands using the <xref:System.IAsyncResult.AsyncWaitHandle%2A> property of the returned <xref:System.IAsyncResult>.
935939
936940
If you use <xref:System.Data.SqlClient.SqlCommand.ExecuteReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A> to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use <xref:System.Data.SqlClient.SqlCommand.ExecuteXmlReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteXmlReader%2A> to read FOR XML queries.
941+
942+
This method ignores the <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property.
937943
938944
939945
@@ -1012,7 +1018,8 @@ A timeout occurred during a streaming operation. For more information about stre
10121018
Because this overload does not support a callback procedure, developers must either poll to determine whether the command has completed, using the <xref:System.IAsyncResult.IsCompleted%2A> property of the <xref:System.IAsyncResult> returned by the <xref:System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery%2A> method; or wait for the completion of one or more commands using the <xref:System.IAsyncResult.AsyncWaitHandle%2A> property of the returned <xref:System.IAsyncResult>.
10131019
10141020
If you use <xref:System.Data.SqlClient.SqlCommand.ExecuteReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A> to access XML data, SQL Server returns any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use <xref:System.Data.SqlClient.SqlCommand.ExecuteXmlReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteXmlReader%2A> to read FOR XML queries.
1015-
1021+
1022+
This method ignores the <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property.
10161023
10171024
10181025
## Examples
@@ -1096,6 +1103,8 @@ A timeout occurred during a streaming operation. For more information about stre
10961103
All errors that occur during the execution of the operation are thrown as exceptions in the callback procedure. You must handle the exception in the callback procedure, not in the main application. See the example in this topic for additional information on handling exceptions in the callback procedure.
10971104
10981105
If you use <xref:System.Data.SqlClient.SqlCommand.ExecuteReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A> to access XML data, SQL Server returns any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use <xref:System.Data.SqlClient.SqlCommand.ExecuteXmlReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteXmlReader%2A> to read FOR XML queries.
1106+
1107+
This method ignores the <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property.
10991108
11001109
11011110
@@ -1186,6 +1195,8 @@ A <see cref="P:System.Data.SqlClient.SqlParameter.SqlDbType" /> other than **Xml
11861195
All errors that occur during the execution of the operation are thrown as exceptions in the callback procedure. You must handle the exception in the callback procedure, not in the main application. See the example in this topic for additional information on handling exceptions in the callback procedure.
11871196
11881197
If you use <xref:System.Data.SqlClient.SqlCommand.ExecuteReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A> to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use <xref:System.Data.SqlClient.SqlCommand.ExecuteXmlReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteXmlReader%2A> to read FOR XML queries.
1198+
1199+
This method ignores the <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property.
11891200
11901201
11911202
@@ -1290,6 +1301,8 @@ SqlCommand command = new SqlCommand("SELECT ContactID, FirstName, LastName FROM
12901301
Because this overload does not support a callback procedure, developers need to either poll to determine whether the command has completed, using the <xref:System.IAsyncResult.IsCompleted%2A> property of the <xref:System.IAsyncResult> returned by the <xref:System.Data.SqlClient.SqlCommand.BeginExecuteXmlReader%2A> method; or wait for the completion of one or more commands using the <xref:System.IAsyncResult.AsyncWaitHandle%2A> property of the returned <xref:System.IAsyncResult>.
12911302
12921303
If you use <xref:System.Data.SqlClient.SqlCommand.ExecuteReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A> to access XML data, SQL Server returns any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use <xref:System.Data.SqlClient.SqlCommand.ExecuteXmlReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteXmlReader%2A> to read FOR XML queries.
1304+
1305+
This method ignores the <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property.
12931306
12941307
12951308
@@ -1384,6 +1397,8 @@ SqlCommand command = new SqlCommand("SELECT ContactID, FirstName, LastName FROM
13841397
All errors that occur during the execution of the operation are thrown as exceptions in the callback procedure. You must handle the exception in the callback procedure, not in the main application. See the example in this topic for additional information on handling exceptions in the callback procedure.
13851398
13861399
If you use <xref:System.Data.SqlClient.SqlCommand.ExecuteReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A> to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use <xref:System.Data.SqlClient.SqlCommand.ExecuteXmlReader%2A> or <xref:System.Data.SqlClient.SqlCommand.BeginExecuteXmlReader%2A> to read FOR XML queries.
1400+
1401+
This method ignores the <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property.
13871402
13881403
13891404
@@ -1703,7 +1718,7 @@ SELECT * FROM dbo.Customers WHERE CustomerID = @CustomerID
17031718
A value of 0 indicates no limit (an attempt to execute a command will wait indefinitely).
17041719
17051720
> [!NOTE]
1706-
> The <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property will be ignored during asynchronous method calls such as <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A>.
1721+
> The <xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> property will be ignored by older APM (Asynchronous Programming Model) asynchronous method calls such as <xref:System.Data.SqlClient.SqlCommand.BeginExecuteReader%2A>. It will be honored by newer TAP (Task Asynchronous Programming) methods such as <xref:System.Data.SqlClient.SqlCommand.ExecuteReaderAsync%2A>.
17071722
17081723
<xref:System.Data.SqlClient.SqlCommand.CommandTimeout%2A> has no effect when the command is executed against a context connection (a <xref:System.Data.SqlClient.SqlConnection> opened with "context connection=true" in the connection string).
17091724

0 commit comments

Comments
 (0)