在创建DataReader对象时使用CommandBehavior.CloseConnection有何作用

SqlDateReader reader=command.ExecuteReader(CommandBehavior.CloseConnection);

由于DataReader对象使用流模式读取数据,数据读取的动作是连续进行的,在具体应用时时很难确定数据库连接何时才能被关闭。

CommandBehavior.CloseConnection解决了流读取数据模式下,数据库连接不能有效关闭的情况。当SqlDataReader对象在生成时使用了CommandBehavior.CloseConnection,那数据库连接将在SqlDataReader对象关闭时自动关闭。

当没有使用CommandBehavior.CloseConnection时关闭SqlDataReader在创建DataReader对象时使用CommandBehavior.CloseConnection有何作用
在创建DataReader对象时使用CommandBehavior.CloseConnection有何作用

当有使用CommandBehavior.CloseConnection时关闭SqlDataReader
在创建DataReader对象时使用CommandBehavior.CloseConnection有何作用
在创建DataReader对象时使用CommandBehavior.CloseConnection有何作用