日期:2014-05-18  浏览次数:20616 次

SqlDateReader对象Close了还要SqlConnection对象Close吗
在类A中使用SqlCommand.ExcuteReader()返回一个SqlDataReader对象,此类中未关闭connection连接

在类B中输出DataReader中的信息完毕后关闭DataReader.Close();此时还要关闭Connection连接吗?
如何关闭

------解决方案--------------------
需要关闭,可以在A类中执行ExcuteReader(CommandBehavior.CloseConnection)获得阅读器,CloseConnection枚举值表示在执行该命令时,如果关闭关联的 DataReader 对象,则关联的 Connection 对象也将关闭。 


------解决方案--------------------
探讨
在类A中使用SqlCommand.ExcuteReader()返回一个SqlDataReader对象,此类中未关闭connection连接

在类B中输出DataReader中的信息完毕后关闭DataReader.Close();此时还要关闭Connection连接吗?
如何关闭