我正在尝试与托管在Amazon Web Services上的MySQL数据库建立稳定的连接。定期启动应用程序时,我会得到以下异常:

由于意外的数据包格式,握手失败

这是一个使用MySQL.Data.dll V6.9.9的WinForm C#应用程序

这是我的连接代码:

        using (var conn = new MySqlConnection(m_connectionString))
        {
            try
            {
                conn.Open();
                Console.WriteLine("Connected to database");
            }
            catch (MySqlException ex)
            {
                validConnectionFound = false;
                Console.WriteLine(ex);
                MessageBox.Show("Unable to connect to Database. Check your network connection and try again", "Database connection Not Found");
            }
            catch (CryptographicException ex)
            {
                validConnectionFound = false;
                MessageBox.Show("Cryptographic Exception: " + ex.Message);
                Environment.Exit(0);
            }
            catch(IOException ex)
            {
                validConnectionFound = false;
                DebugTrace.TraceWrite(m_defaultTraceSource, TraceEventType.Error, "Incorrect certificate. Please update security certificate. Exception: " + ex.Message);
                MessageBox.Show("IO Exception: " + ex.Message);
                Environment.Exit(0);
            }
        }


我的连接字符串采用以下格式:

"user id=user;password=1234;server=amazonserver.com;database=myDatabase;convertzerodatetime=True;port=3306;sslmode=VerifyCA"


我尝试了无线和有线连接,更改了所需的SSL模式(VerifyCA,Required,VerifyFull,无),并将Amazons CA添加到我的计算机受信任的根证书中。

感谢您对我为什么会收到此异常的任何见解。

最佳答案

原来问题与代码无关。用Wireshark嗅探数据包后,我发现问题出在网络交换机故障而丢失了数据包。

关于c# - 由于意外的数据包格式,握手失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45200180/

10-11 06:47
查看更多