Categories
Entity Framework

Multiple Active Results

Recently I was creating a new Web Application using Entity Framework Code First principal. After a while I was getting the hang of it when I got an error message which I couldn’t place and had not seen before. It was of the type EntityCommandExecutionException and the Inner Exception said There is already an open DataReader associated with this Command which must be closed first.

I searched the internet for a solution and finally figured out it came from the connection string. I added MultipleActiveResultsets=True to my connection string and the error message was gone. Example: connectionString="Data Source={SQLServerUrl};InitialCatalog={Database}; Integrated Security=True;MultipleActiveResultsets=True"

The above addition to the connection strings makes it posisble for multiple connection te be open. This is used when you have multiple batches of changes and addition on the same connection.

By Bart van Duinkerken

Driven and energetic consultant and developer with 8+ years of experience working on complex projects with clients across multiple business lines. Fluent in Dutch and English; Self-taught .NET developer; Skilled at bridging the gap between business and IT. Excellent at analyzing business requirements and translating them to development needs. Love working with ambitious people not scared of thinking outside of the box. Enjoy guiding and others understanding business requirements.