asp.net – 如何在web.config中增加执行sql查询的时间

前端之家收集整理的这篇文章主要介绍了asp.net – 如何在web.config中增加执行sql查询的时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我在Web应用程序中运行查询时,我得到一个空值. sql Management Studio中直接相同的查询返回结果.

我认为问题是暂停.如何在Web应用程序中增加执行查询的时间?在我的web.config:connectionstring中,没有超时代码.如果我在那里选择超时,会影响我系统的其他部分吗?

解决方法

你可以做一件事.

>在AppSettings.config中(如果不存在则创建一个),创建一个键值对.
>在代码中拉取值并将其转换为Int32并将其分配给command.TimeOut.

喜欢:-
在appsettings.config中 – >

<appSettings>    
   <add key="sqlCommandTimeOut" value="240"/>
</appSettings>

代码中 – >

command.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["sqlCommandTimeOut"]);

应该这样做.

注意:-
当我从microsoft应用程序块中使用sqlHelper类时,我遇到了大多数超时问题.如果你的代码中有它并且面临超时问题,那么最好使用sqlcommand并设置其超时,如上所述.对于所有其他场景,sqlhelper应该没问题.如果您的客户端可以等待比sqlhelper类提供的更长的时间,您可以继续使用上述技术.

例:-
用这个 –

sqlCommand cmd = new sqlCommand(completequery);

 cmd.CommandTimeout =  Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["sqlCommandTimeOut"]);

 sqlConnection con = new sqlConnection(sqlConnectionString);
 sqlDataAdapter adapter = new sqlDataAdapter();
 con.Open();
 adapter.SelectCommand = new sqlCommand(completequery,con);
 adapter.Fill(ds);
 con.Close();

代替

DataSet ds = new DataSet();
ds = sqlHelper.ExecuteDataset(sqlConnectionString,CommandType.Text,completequery);

更新:另请参阅下面的@Triynko答案.检查一下也很重要.

原文链接:https://www.f2er.com/aspnet/251831.html

猜你在找的asp.Net相关文章