各位大虾好:
    小弟建了个教育资源网站,可不知为什么访问速度很慢,我的首页是用asp作的,而其他的页面是用asp.net作的,感觉起来首页要比其他页面快点,现在小弟不太明白到底是数据库连接的问题,还是本身服务器的速度就不快,这个站点的虚拟主机在广州,现在很疑惑,但感觉网站访问速度就是不快。
网站地址是:http://www.cai-kejian.com。
  
这是一部份源程序,看看,这些有问题么?//数据库的连接string strConnection="user id=用户名;password=密码 ;";
strConnection+="initial catalog=cai-kejian_com;Server=server;";
strConnection+="Connect Timeout=30"; myConn = new SqlConnection(strConnection );
       
        if(!Page.IsPostBack) 
       { 
        ListBind(); //与dataList控件邦定数据
        CurrentPage = 0; 
        ViewState["PageIndex"] = 0; 
        RecordCount = CalculateRecord(); 
        lblRecordCount.Text = RecordCount.ToString(); 
    
 
        PageCount = RecordCount/PageSize; 
        lblPageCount.Text = PageCount.ToString(); 
        ViewState["PageCount"] = PageCount; 
        } 
        
        
     
      } 
 
//分页显示
    public int CalculateRecord() 
    { 
      int intCount; 
   
      myConn.Open();
      string strCount = "select count(*) as co from 我的数据表 where 科目='数学'"; 
      SqlCommand MyComm = new SqlCommand(strCount,myConn); 
      
     
      SqlDataReader dr = MyComm.ExecuteReader();       if(dr.Read()) 
     { 
       intCount = Int32.Parse(dr["co"].ToString()); 
      } 
   else 
     { 
       intCount = 0; 
      } 
     dr.Close(); 
     return intCount; 
      myConn.Close();
   } 
    
   ICollection CreateSource() 
   { 
    
    int StartIndex; 
    
  
     StartIndex = CurrentPage*PageSize; 
     string strSel = "select * from 我的数据表 where 科目='数学'"; 
     DataSet ds = new DataSet(); 
    
     SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,myConn); 
     MyAdapter.Fill(ds,StartIndex,PageSize,"Sheet1"); 
    
     return ds.Tables["Sheet1"].DefaultView; 
   } 
   public void ListBind() 
    { 
     DataList1.DataSource = CreateSource(); 
     DataList1.DataBind(); 
    
     lbnNextPage.Enabled = true; 
     lbnPrevPage.Enabled = true; 
     if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false; 
     if(CurrentPage==0) lbnPrevPage.Enabled = false; 
     lblCurrentPage.Text = (CurrentPage+1).ToString(); 
    
     } 
    
     public void Page_OnClick(Object sender,CommandEventArgs e) 
     { 
       CurrentPage = (int)ViewState["PageIndex"]; 
       PageCount = (int)ViewState["PageCount"]; 
    
       string cmd = e.CommandName; 
 
      switch(cmd) 
      { 
      
       case "first":
       CurrentPage=0;
       break;       
       case "next": 
       if(CurrentPage<(PageCount-1)) CurrentPage++; 
       break; 
       case "pre": 
       if(CurrentPage>0) CurrentPage--; 
       break; 
       case "last":
       CurrentPage=PageCount-1;
       break;
       } 
    
       ViewState["PageIndex"] = CurrentPage; 
    
       ListBind(); 
    
     } 小弟是个初学者,希望各位大虾提出一些宝贵的意见,看看小弟的网站还有哪些问题,小弟在线等待....等待......

解决方案 »

  1.   

    你这还叫慢啊?什么叫快啊!不信你试试我的网站,绝对比你的慢。
    www.ahszsf.com
      

  2.   

    客户端输出的 __viewstate 太大。
      

  3.   

    不是广告吧?:)我的站才叫慢,因为数据较大8000多条,展示数据的时候用DATALIST分页是自己写的,大家看看http://coolhomepages.org/
      

  4.   

    问题在这
    SqlDataReader dr = MyComm.ExecuteReader(); 太多的DataReader严重影响速度的,建议改成datatable再试