如何将CommandTimeout添加到web.config中的连接字符串?
我试过:
<add name="ConnectionString" connectionString="Data Source=;Initial Catalog=;Persist Security Info=True;User ID=sa;Password=sa@123;Connect Timeout=200" providerName="System.Data.SqlClient"/>
</connectionStrings>
这是:
<add name="MyProject.ConnectionString"
connectionString="Data Source=127.0.0.1;Initial Catalog=MyDB;Persist Security Info=True;CommandTimeout=60;User ID=sa;Password=saPassw0rd"
providerName="System.Data.SqlClient" />
但这对我没什么用。
谢谢
发布于 2019-10-25 06:06:35
假设这是一个.NET web应用程序,因为它看起来像一个&它没有在描述/标记中指定。这对于我一直在开发的应用程序是有效的,将DB命令超时设置为15秒:
<connectionStrings>
<add name="ConnectionString"
connectionString="Server=localhost; Port=3306; Database=<DB>;
uid=<usr>; pwd=<pw>; default command timeout=15;"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
默认命令超时将应用程序范围应用于每个单独的DB请求。据我所知,如果没有指定,默认为30秒。。对于web应用程序来说,花费30秒以上的单个DB命令有点极端;重新考虑一下解决方案的架构可能会更好。
https://stackoverflow.com/questions/20683157
复制相似问题