Users Pricing

forum

Home Forums TaskCanceledException bubbling up from async Dapper calls in controllers – MindStick

TaskCanceledException bubbling up from async Dapper calls in controllers

Hemant Patel 91 30 Sep 2026

When a client aborts a request mid-stream, I keep catching TaskCanceledException bubbling out of my controller actions. My current repository pattern looks like this:

public async Task<IActionResult> GetById(int id)
{
    // Shared SqlConnection
    var result = await _db.QueryFirstOrDefaultAsync<Product>(
        "SELECT * FROM Products WHERE Id = @id", new { id });
    return Ok(result);
}

The connection opens inside a using block in the repository, yet the async call still throws on cancellation. Should I be passing a CancellationToken all the way down, or is there a Dapper-specific setting I'm overlooking? I don't want to swallow cancellations silently.


0 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md