2017-07-19 1263 views
0

我試圖與託管在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,None),並將Amazons CA添加到我的計算機受信任的根證書。

任何有關爲什麼我得到這個例外的見解表示讚賞。

回答

0

原來這個問題與代碼無關。在用Wireshark嗅探數據包之後,我發現問題出在一個錯誤的網絡交換機丟失數據包。