用于修复 .NET 应用程序 SQL Server 超时问题并提高执行时间的清单

发布于 2024-07-04 22:50:09 字数 1538 浏览 4 评论 0原文

用于改进 .NET 代码和 SQL Server 之间的执行时间的清单。 任何从基本到奇怪的解决方案都值得赞赏。

代码:

通过 avgbody

使用存储过程调用而不是内联 sql 语句 avgbody

使用活动监视器查找阻塞/锁定 杰·谢泼德

SQL Server:

注意存储过程中的参数嗅探,方法是AlexCuse

请注意通过 马丁·克拉克

使用 Profiler 通过 BradO

将事务超时增加

通过 avgbody

检查服务器的繁忙程度 杰·谢泼德

A checklist for improving execution time between .NET code and SQL Server.
Anything from the basic to weird solutions is appreciated.

Code:

Change default timeout in command and connection by avgbody.

Use stored procedure calls instead of inline sql statement by avgbody.

Look for blocking/locking using Activity monitor by Jay Shepherd.

SQL Server:

Watch out for parameter sniffing in stored procedures by AlexCuse.

Beware of dynamically growing the database by Martin Clarke.

Use Profiler to find any queries/stored procedures taking longer then 100 milliseconds by BradO.

Increase transaction timeout by avgbody.

Convert dynamic stored procedures into static ones by avgbody.

Check how busy the server is by Jay Shepherd.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(8

多情癖 2024-07-11 22:50:10

对于响应时间过长的抱怨,一个奇怪的“解决方案”是有一个更有趣的进度条。 意思是,关注用户的感受。 Windows Vista 等待图标就是一个例子。 快速旋转的圆圈给人一种事情进展得更快的感觉。 谷歌在 Android 上使用了同样的技巧(至少是我见过的版本)。

不过,我建议首先尝试解决技术问题,只有在别无选择时才研究人类行为。

A weird "solution" for complaints on long response time is to have a more interesting progress bar. Meaning, work on the user's feeling. One example is the Windows Vista wait icon. That fast rotating circle gives the feeling things are going faster. Google uses the same trick on Android (at least the version I've seen).

However, I suggest trying to address the technical problem first, and working on human behavior only when you're out of choices.

假面具 2024-07-11 22:50:10

首先也是最重要的 - 检查正在运行的实际查询。 我在通过程序进行设置时使用 SQL Server Profiler,并尽可能检查所有查询是否使用正确的联接和引用键。

First and foremost - Check the actual query being ran. I use SQL Server Profiler as I setup through my program and check that all my queries are using correct joins and referencing keys when I can.

淡墨 2024-07-11 22:50:10

您使用存储过程吗? 如果是这样,您应该注意参数嗅探。 在某些情况下,这可能会导致一些运行时间非常长的查询。 一些阅读:

http://blogs.msdn.com/queryoptteam /archive/2006/03/31/565991.aspx

http://blogs.msdn.com/khen1234/archive/2005/06/02/424228.aspx

Are you using stored procedures? If so you should watch out for parameter sniffing. In certain situations this can make for some very long running queries. Some reading:

http://blogs.msdn.com/queryoptteam/archive/2006/03/31/565991.aspx

http://blogs.msdn.com/khen1234/archive/2005/06/02/424228.aspx

凉世弥音 2024-07-11 22:50:10

我也喜欢使用 SQL Server Profiler。 我喜欢在工作日的 15-30 分钟的时间段内,在数据库服务器上的客户端站点上设置跟踪,并记录持续时间 > 的所有查询/存储过程。 100 毫秒。 无论如何,这就是我对“长时间运行”查询的标准。

I like using SQL Server Profiler as well. I like to setup a trace on a client site on their database server for a good 15-30 minute chunk of time in the midst of the business day and log all queries/stored procs with an duration > 100 milliseconds. That's my criteria anyway for "long-running" queries.

清浅ˋ旧时光 2024-07-11 22:50:10

一些快速的...

  • 检查服务器的处理器使用情况,看看它是否太忙 使用
  • 活动监视器查找是否有阻塞/锁定
  • 网络问题/性能

A few quick ones...

  • Check Processor use of server to see if it's just too busy
  • Look for blocking/locking going on with the Activity monitor
  • Network issues/performance
爱冒险 2024-07-11 22:50:10

运行 Profiler 来测量查询的执行时间。
检查应用程序日志记录是否存在任何死锁。

Run Profiler to measure the execution time of your queries.
Check application logging for any deadlocks.

蝶…霜飞 2024-07-11 22:50:10

适用于 SQL Server 2000 的奇怪做法今天可能仍然适用:

确保您没有尝试在生产环境中动态增长数据库。 到了某个时候,分配额外空间所需的时间和正常负载运行将导致查询超时(而且还会导致查询超时!)

Weird one that applied to SQL Server 2000 that might still apply today:

Make sure that you aren't trying to dynamically grow the database in production. There comes a point where the amount of time it takes to allocate that extra space and your normal load running will cause your queries to timeout (and the growth too!)

内心激荡 2024-07-11 22:50:09

过去我的一些解决方案是:

  1. 修复 sqlcommand 的默认超时设置:

    将 myCommand 调暗为新 SqlCommand("[dbo].[spSetUserPreferences]", myConnection)

    myCommand.CommandType = CommandType.StoredProcedure

    myCommand.CommandTimeout = 120

  2. 增加连接超时字符串:

    数据源=mydatabase;初始目录=匹配;持久安全信息=True;用户ID=用户;密码=密码;连接超时=120

  3. 增加sql-server 2005中的事务超时

    在管理工作室的工具中> 选项> 设计者增加“事务超时时间:”,即使选中/取消选中“覆盖表设计器更新的连接字符串超时值”。

  4. 将动态存储过程转换为静态存储过程

  5. 使代码调用存储过程,而不是在代码中编写内联sql语句。

In the past some of my solutions have been:

  1. Fix the default time out settings of the sqlcommand:

    Dim myCommand As New SqlCommand("[dbo].[spSetUserPreferences]", myConnection)

    myCommand.CommandType = CommandType.StoredProcedure

    myCommand.CommandTimeout = 120

  2. Increase connection timeout string:

    Data Source=mydatabase;Initial Catalog=Match;Persist Security Info=True;User ID=User;Password=password;Connection Timeout=120

  3. Increase transaction time-out in sql-server 2005

    In management studio’s Tools > Option > Designers Increase the “Transaction time-out after:” even if “Override connection string time-out value for table designer updates” checked/unchecked.

  4. Convert dynamic stored procedures into static ones

  5. Make the code call a stored procedure instead of writing an inline sql statement in the code.

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