There is already an open DataReader associated with this Command which must be closed first

前端 未结 18 2328
孤街浪徒
孤街浪徒 2020-11-22 01:40

I have this query and I get the error in this function:

var accounts = from account in context.Accounts
               from guranteer in account.Gurantors
           


        
18条回答
  •  后悔当初
    2020-11-22 02:30

    This is extracted from a real world scenario:

    • Code works well in a Stage environment with MultipleActiveResultSets is set in the connection string
    • Code published to Production environment without MultipleActiveResultSets=true
    • So many pages/calls work while a single one is failing
    • Looking closer at the call, there is an unnecessary call made to the db and needs to be removed
    • Set MultipleActiveResultSets=true in Production and publish cleaned up code, everything works well and, efficiently

    In conclusion, without forgetting about MultipleActiveResultSets, the code might have run for a long time before discovering a redundant db call that could be very costly, and I suggest not to fully depend on setting the MultipleActiveResultSets attribute but also find out why the code needs it where it failed.

提交回复
热议问题