请教各位:
我做了一个Asp.net + C# + Sql2000 环境下的网站,网站运行起来后会发现SQL2000的进程管理里面有40多个sleeping,请问这是我的程序没有关闭数据库连接的问题吗?不过我已经检查了,好象都关闭了.我的网站页面是动态拼装生成的HTML,所以会有很多函数.附代码如下:代码里有con.open() 和 con.Close();(1)-----------------------------------------------------------------------public string GetPictureNews(int Ts,int Sd)//得到图片新闻代码
{   
string  Pnews="";
int  bi=1;
string str_sql="select top "+Ts+" id,title,pdate from news where status like '11%' order by pdate desc";
con.open();
SqlCommand command=new SqlCommand(str_sql,con.myConnection);
SqlDataReader read=command.ExecuteReader(); while(read.Read())
{
if(bi==1)//show pic

Pnews=Pnews+ "<tr><td><a href='webback/article/news_view.aspx?id="+read.GetValue(0).ToString()+"' target='_blank'>"+getpic(read.GetValue(0).ToString())+"</a></td><td width=280 valign='top'><table>";

}
                Pnews=Pnews+"<tr><td>·<a href='webback/article/news_view.aspx?id="+read.GetValue(0).ToString()+"' target='_blank'>"+read.GetValue(1).ToString()+"</a><font color='#99999'>("+System.Convert.ToDateTime(read.GetValue(2)).ToString("m")+")</font></td></tr>";
bi=bi+1;
}
read.Close();
con.Close();
Pnews="<table width='100%' class='border1' cellpadding='0' cellspacing='0'><tr><td colspan='2' height='21' background='images/tbg.jpg' class='Title'><b>&nbsp;&nbsp;焦点信息</b></td></tr>"+Pnews+"</table></tr></table><table><tr><td height='5'></td></tr></table>";
return Pnews.ToString();
}
(2)-----------------------------------------------------------------------------
public void open()

myConnection=new SqlConnection(ConfigurationSettings.AppSettings["connectionstring"]);
myConnection.Open();
}(3)----------------------------------------------------------------------------------
public void Close()
{
if (ds!=null) // 清除DataSet对象
{
ds.Clear();
}
if (myConnection!=null)
{
myConnection.Close(); // 关闭数据库
}
}

解决方案 »

  1.   

    问问楼主,在哪里查看SQL Server的进程?呵呵
      

  2.   

    问问楼主,在哪里查看SQL Server的进程?呵呵
      

  3.   

    查询分析器里有
    use master
     exec sp_who
      

  4.   

    楼主打开页面,按住f5健3分钟,打开查询分析器,键入sp_who
    如果sleeping 超过50,恭喜你,你的网站连接池人多的时候肯定要超时的
      

  5.   

    1、最好用   /// <summary>
    /// 打开连接
    /// </summary>
    private void Open() 
    {
    // 打开连接
    if (con == null || con.State == ConnectionState.Broken || con.State == ConnectionState.Closed) 
    {
    con = new SqlConnection(ConfigurationSettings.AppSettings["BaseDBConn"]);
    con.Open();
    }
    } /// <summary>
    /// 关闭连接
    /// </summary>
    public void Close() 
    {
    if (con != null)
    {
    con.Close();
    con.Dispose();
    }
    }
    调用时用try
    {
    Open();
    SqlCommand cmd = new SqlCommand(sql,con);
    cmd.ExecuteNonQuery();
    }
    catch
    {
    }
    finally
    {
    this.Close();
    }
    2、链接数过多没有关系,一会儿自己会释放掉,我们的网站链接数有时会超过100,一会儿自己会释放
      

  6.   

    连接池的共享缓存吧,不用管,SQLserver有自动清除机制。