C#接口访问超时时间修改
1.数据库连接字符串中添加对数据库的访问时间 Connect Timeout=500 单位秒。默认30秒
eg.
2.web.config中添加executionTimeout 时间,指示在请求被 ASP.NET 自动关闭前允许执行的最大秒数。单位秒 默认90秒,加在httpRuntime标签中。
eg.
3.在接口中设置连接时间,给SqlCommand 的实体设置CommandTimeout 时间.单位秒
eg.
using (SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["SqlConnStr"]))
{
cnn.Open();
SqlCommand command = new SqlCommand();//因需要加长超时时间,使用sqlcommand方法
command.CommandTimeout = 600;//十分钟
//指定Command对象所使用的Connection对象
command.Connection = cnn;
//指定Command对象用于执行SQL语句
command.CommandType = CommandType.Text;
//指定要执行的SQL语句
command.CommandText = totalCountSql;//要执行的SQL语句
//执行查询操作,返回单个值
var count = command.ExecuteScalar().ToString();
dr1.Close();
cnn.Close();