public static SqlDataReader QueryReader(string strSQL)
{
SqlConnection connection = new SqlConnection(connectionString);
//{
SqlCommand cmd = new SqlCommand(strSQL, connection);
try
{//执行数据库命令
DoConn(connection);
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return myReader;
}
catch (Exception e)
{//处理异常
throw new Exception(e.Message);
}
finally
{//释放资源
cmd.Dispose();
//connection.Close();
}
//} }调用这个方法返回一个datareader页面datareader.close()的时候,连接关闭了吗??是不是真的关闭了啊?如何看啊?
{
SqlConnection connection = new SqlConnection(connectionString);
//{
SqlCommand cmd = new SqlCommand(strSQL, connection);
try
{//执行数据库命令
DoConn(connection);
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return myReader;
}
catch (Exception e)
{//处理异常
throw new Exception(e.Message);
}
finally
{//释放资源
cmd.Dispose();
//connection.Close();
}
//} }调用这个方法返回一个datareader页面datareader.close()的时候,连接关闭了吗??是不是真的关闭了啊?如何看啊?
解决方案 »
- 工行支付返回签名验证错误,在线等
- gridview 数据绑定 两张表 怎么弄啊
- 关于在Page_load中传递JS代码的问题!
- 救急啊..关于ASPX页面的响应问题,还有一些关于dotlucene的...帮我看看啊,给点意见啊.
- 如何在datagrid中显示缩略图,点击显示原图大小
- 我是菜鸟,我的iis怎么浏览不了aspx格式的文件
- 怎么在2个数据库之间交互dataset?
- Findcontrol 问题?
- 一段代码,INCLUDE和做成用户控件到底有哪些区别?
- 我的网页总是出现 连接池 超时!如何解决?
- .ENT 生成word 图片怎么插入,在线等待
- 关于tag标签问题,奉100分以谢高手,表达敬意
cmd.Dispose();请问这个是在sqldatareader.close() 之后执行的吗?
-----------------
你打出来看:
if (connection != null)
MessageBox.Show(connection.State.ToString());//closed 关闭,open 打开
我的页面里没有CONNECTION啊,怎么打啊,在SQLHELPER里啊
public static SqlDataReader QueryReader(string strSQL)
{
SqlConnection connection = new SqlConnection(connectionString);
//{
SqlCommand cmd = new SqlCommand(strSQL, connection);
try
{//执行数据库命令
DoConn(connection);
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
myReader.Read();
myReader.close();
if (connection != null)
MessageBox.Show(connection.State.ToString()); return myReader;
}
catch (Exception e)
{//处理异常
throw new Exception(e.Message);
}
finally
{//释放资源
cmd.Dispose();
//connection.Close();
}
//}