Search code examples
c#mysqlperformancetimeoutexception

Performance opening and closing connection vs commandTimeout


I'm using Mysql 5.6.4. c# 4.

Case 1. Just say I setted commandTimeout = 300(5 minutes) and executed in 1 go. and then close the connection.

Case 2. I setted commandTimeout = 150(2.5 minutes) and iterated the same procedure two times(retry count) if timeout exception caught in MySqlException.

So my question is that which one will perform better.


Solution

  • Neither.

    Connect/disconnect time is very small. The "right" way to code is to connect, do everything you need to do, then disconnect.

    If you have a command that is taking "too long", then rethink the command or increase the relevant timeout.

    UPDATEing a million rows as a standard task usually implies a poorly designed schema and data-flow. Let's hear the rationale for it.