Dapper QueryAsync calling SQL Server stored procedure is 3x slower than SSMS (SP ~6s, C# ~17–19s)

19 hours ago 1
ARTICLE AD BOX
public async Task<List<IDictionary<string, object?>>> GetAllDynamicAsync( string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure) { using IDbConnection db = new SqlConnection(Connectionstring); var rows = await db.QueryAsync(sp, parms, commandType: commandType); return rows.Select(r => (IDictionary<string, object?>)r).ToList(); }

I'm calling a SQL Server stored procedure via Dapper. Executing the stored procedure in SSMS takes ~ 6 seconds, but calling it from C# takes ~ 17–19 seconds. The delay appears to be in the QueryAsync call.

The stored procedure returns dynamic columns (pivot-like). The output column set depends on params @dStartDate and @dEndDate (it builds date columns based on the range).

I return dynamic and cast each row to IDictionary<string, object?> because the columns vary.

Result size: ~ 8,000 rows, ~ 25 columns.

SSMS execution time (same params): ~6 seconds.

C# time measured around only this line:

var rows = await db.QueryAsync(sp, parms, commandType: CommandType.StoredProcedure);

and it's consistently ~ 17–19 seconds.

Read Entire Article