adsense

Thursday, June 9, 2016

LINQ Error "There is already an open DataReader associated with this Connection which must be closed first"

When working with link queries I recently got this error message, which states "There is already an open DataReader associated with this Connection which must be closed first" .

This error is caused by an already open connection to the database that is not closed. Adding a .ToList at the end of the LINQ query will resolve this issue.
e.g

 var vacancies = db.Vacancies.Where(v => v.User.Username == userName )
                                                .Take(5)..ToList();



Cheers,
Samitha

 

No comments:

Post a Comment