Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / MySQL

How to fix Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

4.75/5 (8 votes)
2 Aug 2013CPOL 71.6K  
Insert Ignore with select thousands of rows threw timeout expired exception

Using MySQL .NET /Connector with a thousands of rows to do an INSERT IGNORE command results in timeout expired exception. Normally we focus in connection time out or command timeout etc.

But in this case, the problem is with  net_read_timeout, because the command needs to read thousands of rows before to do the task.

The best way to fix it, is to increase the net_read_timeout (by default is only 30 seconds see mysql website) so, you allow the command sufficient seconds to read. If not, the connection will close, because net_read taked more time than the timeout setted.

So you need to type this in any MySQL Console or any User Interface like MySQL Workbench, you need to have administration permissions to change global variables: 

SQL
SET GLOBAL   net_read_timeout = 100

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)