简体   繁体   English

用于将 .NET 应用程序修复为 SQL 服务器超时问题并改善执行时间的清单

[英]A checklist for fixing .NET applications to SQL Server timeout problems and improve execution time

A checklist for improving execution time between .NET code and SQL Server.用于改进 .NET 代码和 SQL 服务器之间的执行时间的清单。 Anything from the basic to weird solutions is appreciated.从基本到奇怪的解决方案的任何东西都值得赞赏。

Code:代码:

Change default timeout in command and connection by avgbody .通过avgbody更改命令和连接中的默认超时。

Use stored procedure calls instead of inline sql statement by avgbody .使用存储过程调用而不是 avgbody 的内联sql语句。

Look for blocking/locking using Activity monitor by Jay Shepherd .使用Jay Shepherd的活动监视器查找阻塞/锁定。

SQL Server: SQL 服务器:

Watch out for parameter sniffing in stored procedures by AlexCuse .注意AlexCuse在存储过程中的参数嗅探。

Beware of dynamically growing the database by Martin Clarke .谨防Martin Clarke的动态增长数据库。

Use Profiler to find any queries/stored procedures taking longer then 100 milliseconds by BradO .使用 Profiler 查找BradO 耗时超过100 毫秒的任何查询/存储过程。

Increase transaction timeout by avgbody .通过avgbody增加事务超时。

Convert dynamic stored procedures into static ones by avgbody .通过 avgbody 将动态存储过程转换为static

Check how busy the server is by Jay Shepherd .查看Jay Shepherd的服务器有多忙。

In the past some of my solutions have been:在过去,我的一些解决方案是:

  1. Fix the default time out settings of the sqlcommand:修复 sql 命令的默认超时设置:

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

    myCommand.CommandType = CommandType.StoredProcedure myCommand.CommandType = CommandType.StoredProcedure

    myCommand.CommandTimeout = 120 myCommand.CommandTimeout = 120

  2. Increase connection timeout string:增加连接超时字符串:

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

  3. Increase transaction time-out in sql-server 2005在 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将动态存储过程转换为 static 的

  5. Make the code call a stored procedure instead of writing an inline sql statement in the code.使代码调用存储过程,而不是在代码中编写内联 sql 语句。

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.一个示例是 Windows Vista 等待图标。 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).谷歌在 Android 上使用了相同的技巧(至少我见过的版本)。

However, I suggest trying to address the technical problem first, and working on human behavior only when you're out of choices.但是,我建议先尝试解决技术问题,然后仅在您别无选择时才研究人类行为。

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/queryoptteam/archive/2006/03/31/565991.aspx

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

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.我在通过程序设置时使用 SQL Server Profiler,并尽可能检查我的所有查询是否使用正确的连接和引用键。

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网络问题/性能

Run Profiler to measure the execution time of your queries.运行 Profiler 以测量查询的执行时间。
Check application logging for any deadlocks.检查应用程序日志记录是否存在任何死锁。

I like using SQL Server Profiler as well.我也喜欢使用SQL Server Profiler 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.我喜欢在工作日中间的 15-30 分钟的时间里,在他们的数据库服务器上的客户端站点上设置跟踪,并记录所有持续时间 > 100 毫秒的查询/存储过程。 That's my criteria anyway for "long-running" queries.无论如何,这就是我对“长期运行”查询的标准。

Weird one that applied to SQL Server 2000 that might still apply today:适用于 SQL Server 2000 的奇怪的一个可能仍然适用于今天:

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!)有一点是,分配额外空间和正常负载运行所需的时间会导致查询超时(以及增长!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM