为什么Sql Server 连接超时

发布于 2024-07-17 10:12:42 字数 735 浏览 3 评论 0原文

我正在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

百善笑为先 2024-07-24 10:12:42

嗯,有几种可能性:

  • 您的查询太复杂并且花费太长时间(尝试编写更好的 TSQL、添加索引或增加超时)
  • 您被另一个 SPID 阻止(也许您自己在另一个连接上)

通常,第二种是问题。 查看阻塞等(sp_who / sp_who2)以查看是否有任何阻塞。 并使用跟踪/分析器来研究第一个选项。

Well, there are a few possibilities:

  • your query is too complex and takes too long (try writing better TSQL, adding indexes, or increasing the timeout)
  • you are being blocked by another SPID (perhaps yourself on another connection)

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.

若言繁花未落 2024-07-24 10:12:42

我认为你设置了不正确的服务器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.

一江春梦 2024-07-24 10:12:42

您是否总是遇到超时,或者仅在执行长时间运行的查询时出现超时? 当您手动运行它时 - 即在管理工作室中,需要多长时间? 您的连接设置为 3 分钟后超时,这是一个非常长的时间。

您需要在几个层面上解决这个问题:

  1. 个人资料和信息。 优化查询
  2. 用非常简单的查询进行测试,看看是否存在连接问题

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:

  1. Profile & Optimize the query
  2. Test with very simple queries to see if there is a connection problem
影子的影子 2024-07-24 10:12:42

我不太熟悉企业数据库,但我会看看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文