Audit Logout cpu:0 reads:29116676 writes 32730 duration 13
……
Audit Logout cpu:0 reads:29116671 writes 32730 duration 16
追踪了一下,结果逻辑读取这么大。谁帮我看一下。是我重复打开的原因吗? 
public string strcon = "Integrated Security=SSPI;Initial Catalog='db123';Data Source='Ghost-1383119';User ID='sa';Password='sa';Connect Timeout=0";
try
{
 SqlConnection conn = new SqlConnection(strcon);
  conn.Open();
  strSQL = "select id,title,keyword from web where id<120 and id>98 order by id asc";
  SqlDataAdapter da = new SqlDataAdapter(strSQL, conn);
  da.SelectCommand.CommandTimeout = 60000;    da.Fill(ds, "web");
  conn.Close();
  n = ds.Tables["web"].Rows.Count;
    
  foreach (DataRow dr in ds.Tables["web"].Rows)
  {
  titleid = dr["id"].ToString();
  if (titleid != null)
  {
  titleid = titleid.ToString();
  }
    
long id = long.Parse(inputid);
  string strNextSQL = "select top 1 id,title,time from web where keyword='" + keyword + "' and id>" + id + " order by id asc";
    
  SqlConnection con = new SqlConnection(strcon);
  con.Open();
  SqlDataAdapter datar = new SqlDataAdapter(strPrevSQL, con);
    
  DataSet ds = new DataSet();
  datar.Fill(ds);
  previd = ds.Tables[0].Rows[1]["id"].ToString();
  prevtitle = ds.Tables[0].Rows[1]["title"].ToString();
  ds = null;
con.Close();SqlConnection mycon = new SqlConnection(strcon);  
  mycon.Open();  long id = long.Parse(inputid);
  string strSQL = "select * from web where id=" + id;
  SqlDataReader dr = null;
  SqlCommand mycommand = new SqlCommand(strSQL, mycon);
  dr = mycommand.ExecuteReader();
  while (dr.Read())
  {
  titleid = dr["id"].ToString();
  title = dr["title"].ToString();
  }
  dr.Close();
  mycommand.CommandText = "update web set show_path=1 where id=" + long.Parse(inputid);   
  mycommand.ExecuteNonQuery();
  mycon.Close();  }

解决方案 »

  1.   

     da.Fill(ds, "web");//我测了一下都是这一行闹的,可是为什么呢????
      

  2.   

    不是这么“看看”就能看出问题所在的,你需要看sql server的执行计划,分析哪里有索引扫描或者全表扫描,看看是否缺索引等等。就sql语句来说,order by也会影响性能
      

  3.   

    sql server的执行计划怎么弄啊?我可以确定sql的语句和索引都没有问题,但是倒是有一次全表扫描,别的我实在看不出哪有问题。
      

  4.   

    是不是我重复打开sql连接的原因啊?