Bug #68284 connectionString character set=gbk; insert binary field error
Submitted: 6 Feb 2013 4:45 Modified: 4 Jun 2015 7:36
Reporter: zhang xuewen Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / MXJ Severity:S3 (Non-critical)
Version:mysql-connector-net-6.6.4 OS:Microsoft Windows
Assigned to: Assigned Account CPU Architecture:Any
Tags: mysql-connector-net-6.6.4 gbk insert binary error

[6 Feb 2013 4:45] zhang xuewen
Description:
connectionString character set=gbk; 
insert binary field error

How to repeat:
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace MysqlTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string cmd;
            while (true)
            {
                try
                {
                    Console.Write(">");
                    cmd = Console.ReadLine();
                    if (cmd == "exit")
                        break;
                    InsertBinary2();
                }
                catch { }
                
            }
        }
        private static readonly string InsertSql = "insert into t1(id,name,f1,f2,guid) values(?id,?name,?a,?b,?guid)";
        private static readonly Random random = new Random();
        public static void InsertBinary2()
        {
            int lenIn = 400000;
            byte[] dataIn = Utils.CreateBlob(lenIn);
            MySqlConnection c = new MySqlConnection();
            try
            {

                c = new MySqlConnection("connection timeout=25; user id=root; " +
              "password=123456; database=test;server=localhost; " +
              "pooling=false;min pool size=5;character set=gbk;max pool size=101");

                c.Open();
                for (int i = 0; i < 1000; i++)
                {
                    using (MySqlCommand cmd = new MySqlCommand(InsertSql, c))
                    {
                        IDbDataParameter prm1 = cmd.CreateParameter();
                        prm1.ParameterName = "id";
                        prm1.DbType = DbType.Int32;
                        prm1.Value = random.Next();

                        cmd.Parameters.Add(prm1);

                        IDbDataParameter prm2 = cmd.CreateParameter();
                        prm2.ParameterName = "name";
                        prm2.DbType = DbType.String;
                        prm2.Value = random.Next().ToString();
                        cmd.Parameters.Add(prm2);

                        IDbDataParameter prm3 = cmd.CreateParameter();
                        prm3.ParameterName = "a";
                        prm3.DbType = DbType.DateTime;
                        prm3.Value = DateTime.Now;
                        cmd.Parameters.Add(prm3);

                        IDbDataParameter prm4 = cmd.CreateParameter();
                        prm4.ParameterName = "b";
                        prm4.DbType = DbType.Binary;
                        prm4.Value = Guid.NewGuid().ToByteArray();
                        cmd.Parameters.Add(prm4);

                        IDbDataParameter prm5 = cmd.CreateParameter();
                        prm5.ParameterName = "guid";
                        prm5.DbType = DbType.Guid;
                        prm5.Value = Guid.NewGuid().ToByteArray();
                        cmd.Parameters.Add(prm5);

                        int rows = cmd.ExecuteNonQuery();
                        //cmd.Prepare();
                        Console.WriteLine("插入行数:{0}", rows);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                c.Close();
            }
        }
        

    }

    /// <summary>
    /// Summary description for Utils.
    /// </summary>
    public class Utils
    {

        public static byte[] CreateBlob(int size)
        {
            byte[] buf = new byte[size];

            Random r = new Random();
            r.NextBytes(buf);
            return buf;
        }
    }
}

Suggested fix:
why:
MySql.Data\MySqlStream.cs(145):

if (packet.Version.isAtLeast(5, 5, 0))
          msg = packet.ReadString(Encoding.UTF8);//why?
        else
          msg = packet.ReadString();
[4 May 2015 7:36] Chiranjeevi Battula
Hello zhang xuewen,

Thank you for the bug report.
I tried to reproduce the issue at my end Visual Studio 2013 (C#.Net), MySQL Connector/Net 6.9.6 but not seeing any issue in inserting data.
Please provide repeatable steps and exact error message for us to confirm this issue at our end.

Thanks,
Chiranjeevi.
[4 May 2015 7:36] Chiranjeevi Battula
screenshot

Attachment: 68284.PNG (image/png, text), 65.72 KiB.

[5 Jun 2015 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".