运行SPR时,ExecuteReader不支持获取MultiExec。

时间:2018-09-19 16:53:55

标签: c# dapper

我写了以下方法

public async Task<DataTable> ExecuteProcedureToDataTableAsync(string spName, object parameters, int? commandTimeout = null, bool userPrefix = false)
    {
        using (var connection = new SqlConnection(_ConnectionString))
        {
            string spNameWithPrefix = GetSpNameWithPrefix(spName, userPrefix);
            var dt = new DataTable();
            _Logger.Debug($"Executing Query: [{spNameWithPrefix}], with params:[{parameters.ToJsonString()}]");
            dt.Load(await connection.ExecuteReaderAsync(spNameWithPrefix, parameters, commandTimeout: commandTimeout, commandType: CommandType.StoredProcedure));
            _Logger.Debug($"Completed Query To DataTable: [{spNameWithPrefix}], result columnCount:[{dt.Columns.Count}], result row count:[{dt.Rows.Count}]");
            return dt;
        }
    }

并像这样调用它:

using (var results = await ExecuteProcedureToDataTableAsync(StoredProcedureFullName, StoredProcedureParams, Timeout, userPrefix: false))
{
    ExportReport(requestModel, results);
}

我得到一个例外:

  

ExecuteExer不支持MultiExec

是否不支持将spr与executeReader配合使用?

1 个答案:

答案 0 :(得分:1)

ExecuteReader不支持多个执行。请改用QueryMultiple