Error in VBA: `[Microsoft] [ODBC Manager] Data source name was not found and the specified driver is not specified by default

I am creating a macro to add data from my Excel worksheet to my MySQL database

But when I run the macro, I get an error:

[Microsoft][ODBC Manager] Data source name not found and no default driver specified

Code:

 Sub UpdateMySQLDatabasePHP() ' For detailed description visit http://www.vbaexcel.eu/ 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 Server_Name = Range("e4").Value ' IP number or servername Database_Name = Range("e1").Value ' Name of database User_ID = Range("h1").Value 'id user or username Password = Range("e3").Value 'Password Tabellen = Range("e2").Value ' Name of table to write to rad = 0 While Range("a6").Offset(rad, 0).Value <> tom TextStrang = tom kolumn = 0 While Range("A5").Offset(0, kolumn).Value <> tom If kolumn = 0 Then TextStrang = TextStrang & Cells(5, 1) & " = '" & Cells(6 + rad, 1) If kolumn <> 0 Then TextStrang = TextStrang & "', " & Cells(5, 1 + kolumn) & " = '" & Cells(6 + rad, 1 + kolumn) kolumn = kolumn + 1 Wend TextStrang = TextStrang & "'" field2 = "cid" field1 = "bid" table1 = "MMbanner" SQLStr = "UPDATE " & Tabellen & " SET " & TextStrang & "WHERE " & Cells(5, 1) & " = '" & Cells(6 + rad, 1) & "'" Set Cn = New ADODB.Connection Cn.Open "Driver={MySQL ODBC 3.51 Driver};Server=" & Server_Name & ";Database=" & Database_Name & _ ";Uid=" & User_ID & ";Pwd=" & Password & ";" Cn.Execute SQLStr rad = rad + 1 Wend Set rs = Nothing Cn.Close Set Cn = Nothing End Sub 
+4
source share
1 answer

There seems to be something wrong with the connection string. do you have mySQL odbc driver installed?

The easiest way to check the connections is to create a text file "New Text Document.txt" and rename the file extension to udl so that you end up with "New Text Document.udl", then open the file. He must show the master Datalink proerties. You can go through the wizard to create and test the connection. to get the connection string. either open the ".udl" file with notepad or change the extension to ".txt" and open it with notepad.

+3
source

Source: https://habr.com/ru/post/1345501/


All Articles