I am using the petapoco.compiled v6.0.441 in my MVC project. This is working fine for all the synchronous operations. But when I try to use the FetchAsync<> it is throwing an error 'Invalid Operation. The Connection is closed'.
//controller
public async Task<ActionResult> Index()
{
IEnumerable<UserEntity> users= await userService.GetAllAsync();
return View(users);
}
//user service
public Task<List<UserEntity>> GetAllAsync()
{
return userrepository.GetAllAsync();
}
//user repo - trial 1
public Task<List<UserEntity>> GetAllAsync()
{
var res = db.FetchAsync<UserEntity>("select query");
return res;
}
also tried
//user repo - trial 2
public async Task<List<UserEntity>> GetAllAsync()
{
var res = await db.FetchAsync<UserEntity>("select query");
return res;
}
Not sure whether the above implementation is correct or I missed something, Do I have to configure petapoco to support Async?
Thanks, Narendra
I see this regularly, it's most likely you're leaking the
dbinstance to multiple threads.Steps to test and confirm. Isolate the web/api and issue a single request. If single requests work, the issue is as described.