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

后端 未结 8 1174
离开以前
离开以前 2021-02-02 00:44

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

Code:

Chan

相关标签:
8条回答
  • 2021-02-02 01:12

    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!)

    0 讨论(0)
  • 2021-02-02 01:16

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-02 01:19

    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
    0 讨论(0)
  • 2021-02-02 01:25

    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.

    0 讨论(0)
  • 2021-02-02 01:28

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

    0 讨论(0)
提交回复
热议问题