Jui*_*est 10 sql asp.net connection-string web-config
当我在Web应用程序中运行查询时,我得到一个null值.SQL Management Studio中直接相同的查询返回结果.
我认为问题是暂停.如何在Web应用程序中增加执行查询的时间?在我的web.config:中connectionstring,没有超时代码.如果我在那里选择超时,会影响我系统的其他部分吗?
小智 11
你可以做一件事.
喜欢: - 在appsettings.config - >
<appSettings>
<add key="SqlCommandTimeOut" value="240"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
在代码 - >
command.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SqlCommandTimeOut"]);
Run Code Online (Sandbox Code Playgroud)
应该这样做.
注意: - 当我从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();
Run Code Online (Sandbox Code Playgroud)
代替
DataSet ds = new DataSet();
ds = SqlHelper.ExecuteDataset(sqlConnectionString, CommandType.Text, completequery);
Run Code Online (Sandbox Code Playgroud)
更新:另请参阅下面的@Triynko答案.检查一下也很重要.
您应该添加httpRuntime块并处理executionTimeout(以秒为单位)。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
...
<system.web>
<httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100" />
</system.web>
...
</configuration>
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅msdn 页面。
| 归档时间: |
|
| 查看次数: |
96362 次 |
| 最近记录: |