- MySQL知识库 :: c#
- When sending large data packets using compression it fails sometimes.
-
Problem
When you attempt to send data packets larger than 16M to a server using compression, it will fail in unpredictable ways. Most likely, the server will disconnect from the client immediately.
Cause
Connector/Net is not properly managing the byte stream when the size of a packet crosses the 16M barrier and we are using compression. A further explanation would require a lengthy explanation of the wire-level protocol.
Solution
Don’t use compressionMore Information
Steps to reproduce behavior:
- Set max_allowed_packet on your server to a value greater than 16 megabytes.
- Create a connection object including “compress=true” on the connection string.
- Create a table with a LONGBLOB column
- Create an array of bytes greater than 16 megabytes long
- Attempt to insert the array of bytes into the table using an insert statement.
MySqlConnection conn = new MySqlConnection(“server=
;uid= ;pwd= ;database= ;compress=true”); conn.Open(); MySqlCommand cmd = new MySqlCommand(“CREATE TABLE Test (testval LONGBLOB)”, conn); cmd.ExecuteNonQuery(); byte[] byteArray = new byte[ 20000000 ]; ….put some values in the array …. cmd.CommandText = “INSERT INTO Test VALUES (?myval)”; cmd.Parameters.Add( “?myval”, byteArray ); cmd.ExecuteNonQuery(); conn.Close()