How to fix: There is already an open DataReader associated with this Connection | C# ASP.NET Error

Опубликовано: 20 Ноябрь 2024
на канале: Mazen Salah
1,009
6

This video shows how to solve an ASP.NET Core MVC Error that says: There is already an open DataReader associated with this Connection which must be closed first.

This C# exception appears in different cases, one of them, which was the case in the video, is with linq queries when you try to loop through linq variables instead of lists. There are also multiple causes of this error, most of them relate to connecting to the database. The solution provided in this video doesn't just apply on C# or asp projects, but rather it should work in any .net project in Visual Studio, like when the error appears in vb (visual basic), f#, or others.

Some people may think that this exception has to do the dotnet version. So some may search: .net6 there is already an open datareader associated with this connection which must be closed first. Others may think that it has to do with azure, mysql, or sqlserver.