1

I wrote the following method

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;
        }
    }

and invoke it like so:

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

and I get the exception:

MultiExec is not supported by ExecuteReader

is it not supported to executeReader with spr ?

Mortalus
  • 10,574
  • 11
  • 67
  • 117

1 Answers1

2

Multiple executions aren't supported by ExecuteReader. Use QueryMultiple instead.

SILENT
  • 3,916
  • 3
  • 38
  • 57
  • but why is it multiple executions its just one spr? – Mortalus Sep 20 '18 at 06:35
  • 2
    @Mortalus Since I can't see your actual input, I can only guess that the way you're structuring your params is whats causing the issue. Is it IEnumerable? Refer to https://github.com/StackExchange/Dapper/blob/1cd3efd89485ccd0bdcc6036eaa5a12a311189fd/Dapper/SqlMapper.cs – SILENT Sep 21 '18 at 03:37
  • Thanks ! That was it .. I assumed that when receiving an object from api action it will be a dynamic object but it was not it was and array of jObjects so it failed .. I had to use dynamicParams – Mortalus Sep 22 '18 at 05:19