title: Error in VBA: Lost Connection to MySQL Server at 'reading authorization packet',system error 2
body: <p>This is the error which I get after my macro executes for about 10 mins. The macro is basically performing the task to update the MySQL database every five seconds.</p>
  
  <p><img src="https://i.stack.imgur.com/rbGeW.png" alt="enter image description here"></p>
  
  <p>What could be wrong?</p>
  
  <p>My macro is as below:</p>
  
  <pre><code>Public RunWhen As Double
  Public Const cRunIntervalSeconds = 10 ' five seconds
  Public Const cRunWhat = "UpdateMarketData"  ' the name of the procedure to run
  
  Sub UpdateMarketData()
  
      Dim Cn As ADODB.Connection
      Dim Server_Name As String
      Dim Database_Name As String
      Dim User_ID As String
      Dim Password As String
      Dim SQLStr As String
      Dim rs As ADODB.Recordset
      Set rs = New ADODB.Recordset
  
      rad = 0
  
  
  
    TextStrang = TextStrang &amp; "'"
    field2 = "cid"
    field1 = "bid"
    table1 = "MMbanner"
  
    For rowCursor = 3 To 4
  
      SQLStr = "UPDATE tbl_MarketData SET Mid = '" &amp; Cells(rowCursor, 2) &amp; "',Bid = '" &amp; Cells(rowCursor, 5) &amp; "',Offer = '" &amp; Cells(rowCursor, 6) &amp; "',DateEntered = '" &amp; Format(DateTime.Now(), "yyyy-MM-dd hh:mm:ss") &amp; "' WHERE IndexCode = '" &amp; Cells(rowCursor, 1) &amp; "'"
      Debug.Print SQLStr
      Set Cn = New ADODB.Connection
  
      Cn.Open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=&lt;Servername&gt;; PORT=Portno; DATABASE=Databasename; USER=Username; PASSWORD=Password; OPTION=0;"
  
      Cn.Execute SQLStr
      rad = rad + 1
    Next
  Set rs = Nothing
  Cn.Close
  Set Cn = Nothing
  
  Call StartTimer
  
  End Sub
  
  
  Sub StartTimer()
      RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
      Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
          Schedule:=True
  End Sub
  
  
  Sub StopTimer()
      On Error Resume Next
      Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
          Schedule:=False
  End Sub
  </code></pre>