There is already an open DataReader associated with this Command which must be closed first的错误解决办法

执行SqlDataReader.Read之后,如果还想用另一个SqlCommand执行Insert或者Update操作的话,会得到一个错误提示:There is already an open DataReader associated with this Command which must be closed first.


解决方法是在ConnectionString中加上一个参数“MultipleActiveResultSets”, 将其值设置为true。

 

 

SqlConnection conn = new SqlConnection("server=s01;database=MOULTONWEB;uid=sa;pwd=cn1234567890;MultipleActiveResultSets=True

你可能感兴趣的:(There is already an open DataReader associated with this Command which must be closed first的错误解决办法)