When you get connection timeouts, it's typically a problem with one of the following:
Network configuration - slow connection between your web server/dev box and the SQL server. Increasing the timeout may correct this, but it'd be wise to investigate the underlying problem.
连接泄漏。正在运行多少个进程?有多少个打开的连接?我不确定原始 ADO.NET 是否执行连接池,在必要时自动关闭连接,比如企业库,或者在配置了所有连接的地方。这可能是转移注意力。但是,在使用 WCF 和 Web 服务时,我遇到过未关闭连接导致超时和其他不可预测行为的问题。
可以尝试的事情:
Do you get a timeout when connecting to the server with SQL Management Studio? If so, network config is likely the problem. If you do not see a problem when connecting with Management Studio, the problem will be in your app, not with the server.
var sscsb = new SqlConnectionStringBuilder(_dbFactory.Database.ConnectionString);
sscsb.ConnectTimeout = 30;
var conn = new SqlConnection(sscsb.ConnectionString);