为什么Sql Server 连接超时
我正在将 Enterprise Library Data 用于我的 Sql 数据库。 我使用的是3.1版本。 我正在使用此代码执行长时间运行的 sp(大约 1 分钟)。
Dim db As SqlDatabase = New SqlDatabase(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("portalConnection").ConnectionString)
db.ExecuteNonQuery("spnametoexecute")
连接字符串看起来像这个
<add name="portalConnection" connectionString="Server=IP;Database=DBName;uid=User;pwd=PWD; Timeout=180;"
providerName="System.Data.SqlClient" />
问题是我总是收到超时异常。 这是为什么 ?
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
I am using Enterprise Library Data for my Sql database. I am using version 3.1.
I am using this code to execute a long running sp (about 1 min).
Dim db As SqlDatabase = New SqlDatabase(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("portalConnection").ConnectionString)
db.ExecuteNonQuery("spnametoexecute")
Connection string looks like this
<add name="portalConnection" connectionString="Server=IP;Database=DBName;uid=User;pwd=PWD; Timeout=180;"
providerName="System.Data.SqlClient" />
Provlem is that I always get a TimeOut Exception. Why Is that ?
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,有几种可能性:
通常,第二种是问题。 查看阻塞等(sp_who / sp_who2)以查看是否有任何阻塞。 并使用跟踪/分析器来研究第一个选项。
Well, there are a few possibilities:
Often, the second is the problem. Look at the blockages etc (sp_who / sp_who2) to see if there are any blocks. And use a trace/profiler to investigate the first option.
我认为你设置了不正确的服务器IP或者你的服务器没有配置好。 检查您的服务器配置中是否允许管道和 tcp/ip。 常常会忘记。
I think you set incorrect server ip or your server doesn't configured as well. Check if your allow Pipes and tcp/ip in configuration of your server. It's very often forgetting.
您是否总是遇到超时,或者仅在执行长时间运行的查询时出现超时? 当您手动运行它时 - 即在管理工作室中,需要多长时间? 您的连接设置为 3 分钟后超时,这是一个非常长的时间。
您需要在几个层面上解决这个问题:
Do you ALWAYS get a timeout, or only when the long-running query executes? When you run it manually - that is, in management studio, how long does it take? Your connection is set to time out in 3 minutes, which is an ENORMOUS amount of time.
You need to attack this at a couple of levels:
我不太熟悉企业数据库,但我会看看 SqlDatabase 对象是否有超时属性。 尝试在代码中设置超时并测试行为。
I'm not too familliar with enterprise data library but I'd see if the SqlDatabase object has a timeout property. Try setting the timeout in your code and test the behaviour.