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

前端 未结 18 2283
孤街浪徒
孤街浪徒 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:17

    For those finding this via Google;
    I was getting this error because, as suggested by the error, I failed to close a SqlDataReader prior to creating another on the same SqlCommand, mistakenly assuming that it would be garbage collected when leaving the method it was created in.

    I solved the issue by calling sqlDataReader.Close(); before creating the second reader.

提交回复
热议问题