In my previous articles I explained How to save images in MySQL database using C# in Windows Forms application and How to retrieve images from MySQL database and display as a slide show in Windows Forms application using C#. While inserting images more than 1 MB in MySQL BLOB column from C#, I got an error- “Packets larger than max_allowed_packet are not allowed”. In this article I will discuss its causes and solution
By default the largest packet that can be sent to the MySQL server is 1 MB. If you try to insert more than 1 MB of data, you will get a MySqlException with message “Packets larger than max_allowed_packet are not allowed.” and ErrorCode -2147467259
- Open “my.ini” file configuration file from MySQL Server folder. In my system it is located in “C:MySQLMySQL Server 5.1”.
- Add max_allowed_packet=5M below the line containing [mysqld] if it is not already there. Where M represents megabytes
- Restart MySQL service. You can use MySQL Administrator to restart MySql. You can start or stop MySQL service using “Service Control” tab in MySQL Administrator window.