1

I couldnt connect my vba to the mysql. can you tell me where did I go wrong? this method raise runtime error "[Microsoft][ODBC Driver Manager]Data source name not found and no default driver specified" my OS is win 7 64 bit and I just installed 64bit ODBC Connector from https://downloads.mysql.com/archives/c-odbc/ but still the error occurs. I also use xampp with no password if that is also need specifying.

Sub SqlConnect()
Dim ReturnArray

Dim Conn As New ADODB.Connection
Dim mrs As New ADODB.Recordset

    Dim DBPath As String
    Dim sconnect As String


    DBPath = ThisWorkbook.FullName

    sconnect = "DRIVER={MySQL ODBC 5.2.2 Driver}; SERVER = localhost;" & _
        "PORT=3306;" & _
        "DATABASE= timeintimeoutdb;" & _
        "UID=root;" & _
        "PWD=;"




    Conn.Open sconnect
        sqlstring = "SELECT * FROM [students]"
        mrs.Open sqlstring, Conn
        ActiveSheet.Range("A2").CopyFromRecordset mrs
        mrs.Close


    Conn.Close
    End Sub
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Pamingkas Sevada
  • 432
  • 9
  • 21
  • 1
    If your Office is 32-bit then you need the 32-bit MySQL driver. Most (?) Office installs are 32-bit. – Tim Williams Sep 27 '18 at 06:44
  • The connection string is fine. Either driver version (current is MySQL ODBC 8.0 Unicode Driver) or you have database, uid or pwd wrong. – Prakash Gautam Sep 28 '18 at 11:43
  • This is a rather common error, as @TimWilliams pointed out the driver Version (32-bit) depends on you installed Office Version and not your OS Version, which is rather counterintuitive. Detailed explanation: https://stackoverflow.com/questions/17115632/microsoftodbc-driver-manager-data-source-name-not-found-and-no-default-drive – G.M Oct 25 '19 at 07:29

0 Answers0