Skip to content

Commit c4c2f9e

Browse files
mdaigleCopilot
andauthored
Correct SqlBatch command behavior exception documentation (#4878)
Align validator and reader documentation with ArgumentOutOfRangeException and supported batch behavior values without changing runtime behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ad84379d-8a20-4ea9-adbb-bd206096530a
1 parent 2a6039e commit c4c2f9e

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

  • doc/snippets/Microsoft.Data.SqlClient
  • src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient

‎doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,16 @@
235235
<ExecuteReader name="BehaviorParameter">
236236
<param name="behavior">
237237
An instance of <see cref="T:System.Data.CommandBehavior" />, specifying options for batch execution and data retrieval.
238-
Only <see cref="F:System.Data.CommandBehavior.SequentialAccess"/> and <see cref="F:System.Data.CommandBehavior.CloseConnection"/> are supported at the batch level.
238+
Supported values at the batch level are <see cref="F:System.Data.CommandBehavior.Default"/>,
239+
<see cref="F:System.Data.CommandBehavior.SequentialAccess"/>, <see cref="F:System.Data.CommandBehavior.CloseConnection"/>,
240+
or a bitwise combination of <see cref="F:System.Data.CommandBehavior.SequentialAccess"/> and <see cref="F:System.Data.CommandBehavior.CloseConnection"/>.
239241
</param>
240242
<summary>
241243
Sends the <see cref="P:Microsoft.Data.SqlClient.SqlBatch.Commands" /> to the <see cref="P:Microsoft.Data.SqlClient.SqlCommand.Connection" /> and builds a <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" />.
242244
</summary>
245+
<exception cref="T:System.ArgumentOutOfRangeException">
246+
The <paramref name="behavior" /> value is invalid or is not supported at the batch level.
247+
</exception>
243248
<example>
244249
<para>
245250
The following example creates a <see cref="T:Microsoft.Data.SqlClient.SqlConnection" /> and a <see cref="T:Microsoft.Data.SqlClient.SqlBatch" />, then adds multiple <see cref="T:Microsoft.Data.SqlClient.SqlBatchCommand" /> objects to the batch. It then executes the batch, creating a <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" />. The example reads through the results of the batch commands, writing them to the console. Finally, the example closes the <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" /> and then the <see cref="T:Microsoft.Data.SqlClient.SqlConnection" /> as the <c>using</c> blocks fall out of scope.
@@ -293,35 +298,34 @@
293298
<param name="cancellationToken">A token to cancel the asynchronous operation.</param>
294299
<summary>
295300
An asynchronous version of <see cref="M:Microsoft.Data.SqlClient.SqlBatch.ExecuteReader" />, which sends the <see cref="P:Microsoft.Data.SqlClient.SqlBatch.Commands" /> to the <see cref="P:Microsoft.Data.SqlClient.SqlBatch.Connection" /> and builds a <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" />.
296-
Exceptions will be reported via the returned Task object.
301+
Operational exceptions are reported via the returned task; usage exceptions are thrown synchronously.
297302
</summary>
298303
<returns>A task representing the asynchronous operation.</returns>
299304
<exception cref="T:Microsoft.Data.SqlClient.SqlException">
300305
An error occurred while executing the batch.
301306
</exception>
302-
<exception cref="T:System.ArgumentException">
303-
The <see cref="T:System.Data.CommandBehavior" /> value is invalid.
304-
</exception>
305307
<exception cref="T:System.OperationCanceledException">
306308
The cancellation token was canceled. This exception is stored into the returned task.
307309
</exception>
308310
</ExecuteReaderAsync>
309311
<ExecuteReaderAsync name="BehaviorParameter">
310312
<param name="behavior">
311313
An instance of <see cref="T:System.Data.CommandBehavior" />, specifying options for batch execution and data retrieval.
312-
Only <see cref="F:System.Data.CommandBehavior.SequentialAccess"/> and <see cref="F:System.Data.CommandBehavior.CloseConnection"/> are supported at the batch level.
314+
Supported values at the batch level are <see cref="F:System.Data.CommandBehavior.Default"/>,
315+
<see cref="F:System.Data.CommandBehavior.SequentialAccess"/>, <see cref="F:System.Data.CommandBehavior.CloseConnection"/>,
316+
or a bitwise combination of <see cref="F:System.Data.CommandBehavior.SequentialAccess"/> and <see cref="F:System.Data.CommandBehavior.CloseConnection"/>.
313317
</param>
314318
<param name="cancellationToken">A token to cancel the asynchronous operation.</param>
315319
<summary>
316320
An asynchronous version of <see cref="M:Microsoft.Data.SqlClient.SqlBatch.ExecuteReader" />, which sends the <see cref="P:Microsoft.Data.SqlClient.SqlBatch.Commands" /> to the <see cref="P:Microsoft.Data.SqlClient.SqlBatch.Connection" /> and builds a <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" />.
317-
Exceptions will be reported via the returned Task object.
321+
Operational exceptions are reported via the returned task; usage exceptions are thrown synchronously.
318322
</summary>
319323
<returns>A task representing the asynchronous operation.</returns>
320324
<exception cref="T:Microsoft.Data.SqlClient.SqlException">
321325
An error occurred while executing the batch.
322326
</exception>
323-
<exception cref="T:System.ArgumentException">
324-
The <see cref="T:System.Data.CommandBehavior" /> value is invalid.
327+
<exception cref="T:System.ArgumentOutOfRangeException">
328+
The <paramref name="behavior" /> value is invalid or is not supported at the batch level. This exception is thrown synchronously.
325329
</exception>
326330
<exception cref="T:System.OperationCanceledException">
327331
The cancellation token was canceled. This exception is stored into the returned task.
@@ -381,7 +385,9 @@
381385
<ExecuteDbDataReader>
382386
<param name="behavior">
383387
An instance of <see cref="T:System.Data.CommandBehavior" />, specifying options for batch execution and data retrieval.
384-
Only <see cref="F:System.Data.CommandBehavior.SequentialAccess"/> and <see cref="F:System.Data.CommandBehavior.CloseConnection"/> are supported at the batch level.
388+
Supported values at the batch level are <see cref="F:System.Data.CommandBehavior.Default"/>,
389+
<see cref="F:System.Data.CommandBehavior.SequentialAccess"/>, <see cref="F:System.Data.CommandBehavior.CloseConnection"/>,
390+
or a bitwise combination of <see cref="F:System.Data.CommandBehavior.SequentialAccess"/> and <see cref="F:System.Data.CommandBehavior.CloseConnection"/>.
385391
</param>
386392
<summary>
387393
Executes the batch against its connection, returning a <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" /> which can be used to access the results.
@@ -400,14 +406,16 @@ When the batch returns multiple result sets from different commands, <xref:Micro
400406
<exception cref="T:Microsoft.Data.SqlClient.SqlException">
401407
An error occurred while executing the batch.
402408
</exception>
403-
<exception cref="T:System.ArgumentException">
404-
The <see cref="T:System.Data.CommandBehavior" /> value is invalid.
409+
<exception cref="T:System.ArgumentOutOfRangeException">
410+
The <paramref name="behavior" /> value is invalid or is not supported at the batch level.
405411
</exception>
406412
</ExecuteDbDataReader>
407413
<ExecuteDbDataReaderAsync>
408414
<param name="behavior">
409415
An instance of <see cref="T:System.Data.CommandBehavior" />, specifying options for batch execution and data retrieval.
410-
Only <see cref="F:System.Data.CommandBehavior.SequentialAccess"/> and <see cref="F:System.Data.CommandBehavior.CloseConnection"/> are supported at the batch level.
416+
Supported values at the batch level are <see cref="F:System.Data.CommandBehavior.Default"/>,
417+
<see cref="F:System.Data.CommandBehavior.SequentialAccess"/>, <see cref="F:System.Data.CommandBehavior.CloseConnection"/>,
418+
or a bitwise combination of <see cref="F:System.Data.CommandBehavior.SequentialAccess"/> and <see cref="F:System.Data.CommandBehavior.CloseConnection"/>.
411419
</param>
412420
<param name="cancellationToken">A token to cancel the asynchronous operation.</param>
413421
<summary>
@@ -419,13 +427,16 @@ When the batch returns multiple result sets from different commands, <xref:Micro
419427
<![CDATA[
420428
For more information about asynchronous programming, see [Asynchronous Programming](https://learn.microsoft.com/sql/connect/ado-net/asynchronous-programming).
421429
422-
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.Data.Common.DbBatch.ExecuteDbDataReader(System.Data.CommandBehavior)>.
430+
This method stores exceptions in the task it returns, including exceptions for invalid or unsupported behavior values. These exceptions are thrown when the task is awaited. For possible exceptions, see <xref:Microsoft.Data.SqlClient.SqlBatch.ExecuteReader(System.Data.CommandBehavior)>.
423431
424432
> [!NOTE]
425433
> This method benefits from <xref:Microsoft.Data.SqlClient.SqlCommand.ExecuteReaderAsync(System.Threading.CancellationToken)>, and all the expected exceptions of that method also apply here.
426434
]]>
427435
</format>
428436
</remarks>
437+
<exception cref="T:System.ArgumentOutOfRangeException">
438+
The <paramref name="behavior" /> value is invalid or is not supported at the batch level. This exception is stored in the returned task.
439+
</exception>
429440
<exception cref="T:System.OperationCanceledException">
430441
The cancellation token was canceled. This exception is stored into the returned task.
431442
</exception>

‎src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatch.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,16 @@ private void SetupBatchCommandExecute()
371371
/// <param name="behavior">The behavior flags to validate.</param>
372372
/// <remarks>
373373
/// <para>
374-
/// Only <see cref="CommandBehavior.SequentialAccess"/> and <see cref="CommandBehavior.CloseConnection"/>
375-
/// are supported at the batch level.
374+
/// Supported values at the batch level are <see cref="CommandBehavior.Default"/>,
375+
/// <see cref="CommandBehavior.SequentialAccess"/>, <see cref="CommandBehavior.CloseConnection"/>,
376+
/// or a bitwise combination of <see cref="CommandBehavior.SequentialAccess"/> and <see cref="CommandBehavior.CloseConnection"/>.
376377
/// </para>
377378
/// <para>
378379
/// To apply other behaviors (such as <see cref="CommandBehavior.SingleRow"/> or <see cref="CommandBehavior.SchemaOnly"/>),
379380
/// they must be set on individual <see cref="SqlBatchCommand"/> instances within the batch.
380381
/// </para>
381382
/// </remarks>
382-
/// <exception cref="NotSupportedException">Thrown when unsupported behavior flags are detected.</exception>
383+
/// <exception cref="ArgumentOutOfRangeException">Thrown when the behavior value is invalid or unsupported at the batch level.</exception>
383384
internal static void ValidateExecuteCommandBehavior(string method, CommandBehavior behavior)
384385
{
385386
if (0 != (behavior & ~(CommandBehavior.SequentialAccess | CommandBehavior.CloseConnection)))

0 commit comments

Comments
 (0)