查询超时:操作完成之前经过的超时时间或服务器没有响应

时间:2017-01-25 04:47:11

标签: sql-server-2008

string cs_insert1 = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;

using (SqlConnection ObjCon_insert1 = new SqlConnection(cs_insert1))
{
    ObjCon_insert1.Open();
    string inserStr1 = "Update Attendence set calculate='calculated' calculate!='calculated' and rollno=@rollno and program=@program and batch=@batch and term=@term";

    SqlCommand inserCmd1 = new SqlCommand(inserStr1, ObjCon_insert1);
    inserCmd1.CommandType = CommandType.Text;
    inserCmd1.Parameters.AddWithValue("@rollno", drsg_final["rollno"].ToString());        
    inserCmd1.Parameters.AddWithValue("@program", drsg_final["program"].ToString());
    inserCmd1.Parameters.AddWithValue("@batch", drsg_final["batch"].ToString());
    inserCmd1.Parameters.AddWithValue("@term", drsg_final["term"].ToString());         

    inserCmd1.ExecuteNonQuery();
}

错误:

  

超时已过期。完成之前已经过了超时时间   操作或服务器没有响应。

我的数据库有超过600 000行,所以当我尝试更新上述查询时,我收到了超时错误

表格结构:

tid         primary key
rollno      varchar
program     varchar
batch       varchar
term        varchar
calculate   varchar
location    varchar
createdby   varchar

指数:

 CREATE INDEX MasterIndex  
 ON Attendence (location, createdby, program, batch, term)

查询:

Update Attendence 
set calculate = 'calculated' 
from Attendence WITH (INDEX (MasterIndex)) 
where calculate != 'calculated' 
  and rollno = @rollno 
  and program = @program 
  and batch = @batch 
  and term = @term

还有其他方法可以更快地处理查询吗?

我正在做正确的索引吗?

我知道我的问题是重复的,但是在问题仍然存在之后尝试了SqlCommand.CommandTimeout=300之类的所有解决方案。

0 个答案:

没有答案