---
title: "TaskCanceledException bubbling up from async Dapper calls in controllers"  
description: "TaskCanceledException bubbling up from async Dapper calls in controllers"  
author: "Hemant Patel"  
published: 2026-09-30  
updated: 2026-09-30  
canonical: https://www.mindstick.com/forum/162227/taskcanceledexception-bubbling-up-from-async-dapper-calls-in-controllers  
category: "Concurrency"  
tags: ["Dapper", "asp.net core", "Async Programming", "Cancellation"]  
reading_time: 1 minute  

---

# TaskCanceledException bubbling up from async Dapper calls in controllers

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:

```cs
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.


---

Original Source: https://www.mindstick.com/forum/162227/taskcanceledexception-bubbling-up-from-async-dapper-calls-in-controllers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
