using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Text; 
using MySql.Data; 
using MySQLDriverCS; 
namespace 动态定位 

    public partial class 服务器端 : System.Web.UI.Page 
    { 
  public MySQLConnection connmysql = new MySQLConnection(new MySQLConnectionString("127.0.0.1", "task", "root", "").AsString); 
      
public MySQLCommand commandmysql; 
        public MySQLDataAdapter adaptermysql; 
      
public DataTable trackdt = new DataTable("trackdt"); 
      
public string flag = "F"; //用于分割数据的标志位 
        
public string nodestrsql = "select * from locatenode order by result_time";//as A where result_time =(select max(result_time) from sensornode where nodeid = A.nodeid)  "; 
        
  protected void Page_Load(object sender, EventArgs e) 
        { 
        if (Request.QueryString["freshing"]=="true") 
          { senddata(); } 
        } 
public void senddata()//这个函数由于客户端的请求每隔10秒执行一次 
                            { 
                              if (connmysql != null) 
                                { 
                                    connmysql.Open(); 
                                    if (commandmysql != null) 
                                        commandmysql.Dispose(); 
                                    commandmysql = new MySQLCommand(nodestrsql, connmysql); 
                                    if (adaptermysql != null) 
                                        adaptermysql.Dispose(); 
                                    adaptermysql = new MySQLDataAdapter(commandmysql); 
                                    trackdt.Clear(); 
                                    adaptermysql.Fill(trackdt); 
                                    connmysql.Close(); 
                                  } 
                              int trackrowcount = trackdt.Rows.Count; 
                              Response.ClearContent(); 
                              Response.Write(trackrowcount); 
                                Response.End(); 
                              } 
                      } 

这个程序是根据客户端的要求定时地读取数据库,而数据库中的数据是随着时间而变化的。但是我发现trackrowcount老是保持第一次执行时的值,并不随着数据库的变化而变为相应的值。当我重新运行整个程序的时候,trackrowcount的确实正确的。这是是为什么,各位大侠帮帮忙啊!是不是非托管资源释放问题惹的祸!!

解决方案 »

  1.   

    检查if (Request.QueryString["freshing"]=="true") 这里是否命中...
    检查if (connmysql != null) 是否命中...
    我是说,你需要确认你的if块里的代码有执行...
      

  2.   

    呵呵,debug一下。看看每次执行的sql语句对不。
      

  3.   

    怪事!
    从昨天上午我一直调试到夜晚10:45(准确)的时候,突然trackdt.Rows.Count反应真确,很兴奋。但是今天早晨起来的时候,重新调试了一下,发现又不行了,很郁闷!
      

  4.   

    除了单步调试验证sql的正确性外,还建议在aspx文件顶部添加去客户端缓存的代码.