我正试图与托管在上的MySQL数据库保持稳定的连接。在启动应用程序时,我会周期性地得到异常:
由于意外的数据包格式,握手失败
这是一个使用WinForm V6.9.9的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、None),并将Amazons添加到我的计算机中,信任根证书。
任何关于我为什么要得到这个例外的洞察力都是值得赞赏的。
发布于 2017-07-21 16:38:18
结果发现这个问题与代码无关。在用Wireshark嗅探数据包之后,我发现问题在于一个错误的网络交换机丢失了数据包。
https://stackoverflow.com/questions/45200180
复制相似问题