sqlserver connection timeout is NOT query timeout


I hit a problem of query timeout. This is a freaking old problem but just that we need to understand differences between connect timeout and query time out. If you don't you find yourself setting a connection string and getting exception over and over again.

The main different is message your get as shown here :-

Connection time out and its exception message.

System.Data.SqlClient.SqlException: Connection Timeout Expired. The timeout period elapsed while …
To solve this you can change the connection string which is pretty straight forward; 

'Connection timeout=3600'


Query timeout and its exception message

System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior …

With this, you can use Command.Timeout or if it is a SQL statement execute statement, you can pass in the connection timeout value.






Comments

Popular posts from this blog

PySpark - Working with JDBC Sqlite database