【问题标题】:timeout on query against small table对小表的查询超时
【发布时间】:2011-06-21 00:38:08
【问题描述】:

我正在尝试执行一个查询,该查询从表中获取所有 ID,其中列 document(varbinary(max)) is null

查询总是超时,我正在对一个 5000 行的表运行它。

select ID from Invoice where Document is null

我正在使用 SQL Express 2008 R2 和 Sql Management Studio。这是正确的方法吗?我错过了什么吗?即使我添加前 1 个查询超时

【问题讨论】:

  • 这对我来说很好。不知道为什么它会超时。如果我可以问,哪个 RDBMS?
  • 我正在使用 SQL Server 2008 r2 Express
  • 您是从 SQL Management Studio 还是从客户端代码运行它?
  • 请复制/粘贴确切的错误信息,或截图。
  • any 查询是否通过 SSMS 针对该服务器实例中任何数据库中的任何表工作?

标签: sql tsql sql-server-2008 timeout


【解决方案1】:
If connecting on localhost Then

    If connecting from Management Studio Then

        Try restarting SQL Server services...could be locks.
        Try restarting machine...could be locks.

    ElseIf connecting from remote app code Then

        Check if SQL Server is setup for remote connections.
        Check connection strings.
        Check seccurity privleges.
        Check log file.

    End If

Else
             Check if SQL Server is setup for remote connections
        Check connection strings.
        Check seccurity privledges.

End If

【讨论】:

  • 当活动较少时,我将尝试在大约一个小时后重新启动服务。我让你知道结果。谢谢
  • 我重启了服务,同样的事情发生了
  • 您是否能够从数据库中的任何表中执行任何选择?...也尝试使用 SELECT TOP 1 只返回一行...或使用 WHERE 子句...如果没有上面的工作,那么你很多有连接或安全问题。
【解决方案2】:

这样做,只读外观

select ID from Invoice (nolock) where Document is null

【讨论】:

  • 你似乎知道这个nolock,你知道为什么表会被锁定吗?有什么好的解释吗?
【解决方案3】:

有时表格会被锁定。尝试在界面中远离选定的表格单击。

您使用的是什么 RDBMS? SQL服务器?赛贝斯?或者..

当你这样做时它仍然超时吗:?

SELECT TOP 10 ID
from Invoice where Document is null

【讨论】:

  • 我正在使用 SQL Server 2008 r2 Express
  • @alenhandrobog:尝试像我建议的那样添加TOP 子句,如果您仍然遇到超时,请告诉我们。
  • @alejandrobog:请编辑您的问题以包括您如何运行此查询。也许包括关于 TOP 的详细信息,为了您的问题的完整性,不返回任何内容。
猜你喜欢
  • 1970-01-01
  • 2012-05-07
  • 1970-01-01
  • 1970-01-01
  • 2020-09-07
  • 1970-01-01
  • 2011-05-17
  • 2020-05-27
  • 1970-01-01
相关资源
最近更新 更多