SqlCommand.ExecuteScalarAsync(CancellationToken) 方法

定义

ExecuteScalar() 的异步版本,该版本异步执行查询,并返回由查询返回的结果集中的第一行的第一列。An asynchronous version of ExecuteScalar(), which executes the query asynchronously and returns the first column of the first row in the result set returned by the query. 忽略其他列或行。Additional columns or rows are ignored.

取消标记可用于在命令超时超过前请求放弃操作。The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. 将通过返回的任务对象报告异常。Exceptions will be reported via the returned Task object.

public:
 override System::Threading::Tasks::Task<System::Object ^> ^ ExecuteScalarAsync(System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task<object> ExecuteScalarAsync (System.Threading.CancellationToken cancellationToken);
override this.ExecuteScalarAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<obj>
Public Overrides Function ExecuteScalarAsync (cancellationToken As CancellationToken) As Task(Of Object)

参数

cancellationToken
CancellationToken

取消指令。The cancellation instruction.

返回

Task<Object>

表示异步操作的任务。A task representing the asynchronous operation.

例外

Value 设置为 Stream 时,使用的是 SqlDbType 而不是 Binary 或 VarBinary。A SqlDbType other than Binary or VarBinary was used when Value was set to Stream. 有关流式处理的详细信息,请参阅 SqlClient 流支持For more information about streaming, see SqlClient Streaming Support.

- 或 --or-

SqlDbType当设置为时,使用的是不是 CharNCharNVarCharVarCharXml Value TextReaderA SqlDbType other than Char, NChar, NVarChar, VarChar, or Xml was used when Value was set to TextReader.

- 或 --or-

Value 设置为 XmlReader 时,使用的是 SqlDbType 而不是 Xml。A SqlDbType other than Xml was used when Value was set to XmlReader.

在完成任务前,为同一个实例多次调用 ExecuteScalarAsync(CancellationToken)Calling ExecuteScalarAsync(CancellationToken) more than once for the same instance before task completion.

- 或 --or-

流式处理操作期间关闭或删除了 SqlConnectionThe SqlConnection closed or dropped during a streaming operation. 有关流式处理的详细信息,请参阅 SqlClient 流支持For more information about streaming, see SqlClient Streaming Support.

- 或 --or-

在连接字符串中指定 Context Connection=trueContext Connection=true is specified in the connection string.

执行命令文本时,SQL Server 返回了一个错误。SQL Server returned an error while executing the command text.

- 或 --or-

流式处理操作期间发生了超时。A timeout occurred during a streaming operation. 有关流式处理的详细信息,请参阅 SqlClient 流支持For more information about streaming, see SqlClient Streaming Support.

流式处理操作期间在 StreamXmlReaderTextReader 对象中出现了错误。An error occurred in a Stream, XmlReader or TextReader object during a streaming operation. 有关流式处理的详细信息,请参阅 SqlClient 流支持For more information about streaming, see SqlClient Streaming Support.

流式处理操作期间关闭了 StreamXmlReaderTextReader 对象。The Stream, XmlReader or TextReader object was closed during a streaming operation. 有关流式处理的详细信息,请参阅 SqlClient 流支持For more information about streaming, see SqlClient Streaming Support.

注解

有关 SQL Server 的 .NET Framework 数据提供程序中的异步编程的详细信息,请参阅 异步编程For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.

适用于