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有何作用

相关文章:

  • 2022-12-23
  • 2021-05-16
  • 2021-12-20
  • 2021-08-29
  • 2021-10-14
  • 2021-09-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案