Unable to connect to MySQL database - no default driver specified - mysql

I'm trying to connect to a MySQL database from within a VBS script, but I can't get passes a specific error -
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I'm running 64-bit Windows 7 (from where the script is running), and the MySQL DB is running on 32-bit Linux. I've tried both the 32- and 64-bit drivers on Windows 7, downloaded from the Download Connector/ODBC page on the MySQL website, but the error persists.
I have found a couple of pages about this issue (including this one), but I've been unable to resolve my issue. How can I make the DB connection I require?
Dim Connection : Set Connection = CreateObject("ADODB.Connection")
Dim RS : Set RS = CreateObject("ADODB.Recordset")
Dim dbConStr : dbConStr = "Driver={MySQL ODBC 5.3.6 Driver};Server=https://mysqlserver.mydomain.com;Data Source=dsn_hb; Database=MyDatabase; User=MyUser; Password=MyPassword;"
Connection.Open dbConStr
RS.open "SELECT * FROM apklibrary.djg_local_archive_scans", Connection, 3
RS.MoveFirst
While Not RS.EOF
Call MsgBox (RS.Fields(0), vbOkOnly, "POW!")
RS.MoveNext
Wend
Connection.close
Set Connection = Nothing
Set RS = Nothing
Call MsgBox ("No more records to show you.", vbOkOnly, "Job done")

The specified driver name is invalid. Valid MyODBC 5.3 driver names:
{MySQL ODBC 5.3 ANSI Driver}
{MySQL ODBC 5.3 Unicode Driver}
Another problem is Server. You should specify the server's address without https://.
Also, since you have user name and password Data Source=dsn_hb; looks redundant, remove it. If not please give us more detail.
So, give a try this:
dbConStr = "DRIVER={MySQL ODBC 5.3 Unicode Driver};Server=mysqlserver.mydomain.com;Database=MyDatabase;User=MyUser;Password=MyPassword;"

Related

How to INSERT/SELECT data from MySQL to Excel/VBA?

I'm trying to extract data from MySQL to Excel. I saw a lot of tutorials but I get the same error all the time.
Here is my code:
Sub consultdate()
Dim conn As New ADODB.Connection
Dim server_name As String
Dim database_name As String
Dim user_id As String
Dim password As String
Dim i As Long
Dim sqlstr As String
Dim table1 As String, table2 As String
Dim field1 As String, field2 As String
Dim rs As ADODB.Recordset
Dim vtype As Variant
server_name = "localhost"
database_name = "controle_fin"
user_id = "root"
password = "userpassword"
Set conn = New ADODB.Connection
conn.Open "DRIVER={MySQL ODBC 3.51 Driver}" _
& ";SERVER=" & server_name _
& ";DATABASE=" & database_name _
& ";UID=" & user_id _
& ";PWD=" & password _
& ";OPTION=16427"
table1 = "classe"
GoTo skipextract
Set rs = New ADODB.Recordset
sqlstr = "SELECT * FROM " & table1
rs.Open sqlstr, conn, adOpenStatic
Planilha1.Range("A1").CopyFromRecordset rs
skipextract:
On Error Resume Next
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
On Error GoTo 0
End Sub
Error that I got:
"ODBC Error. Data Source Name Not Found and No Default Driver Specified"
Typically, this error is due to the following reasons:
Simple Misspelling: ODBC driver names must be exactly spelled correctly and fully including special characters. To see all ODBC drivers, open up PowerShell window and type: Get-OdbcDriver | Format-Table name, platform -AutoSize to output a table similar to below:
name platform
---- --------
Microsoft Access Driver (*.mdb) 32-bit
Microsoft dBase Driver (*.dbf) 32-bit
Microsoft Excel Driver (*.xls) 32-bit
Microsoft ODBC for Oracle 32-bit
SQL Server 32-bit
SQL Server Native Client 11.0 32-bit
ODBC Driver 13 for SQL Server 32-bit
SQL Server 64-bit
Microsoft Access Driver (*.mdb, *.accdb) 64-bit
Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb) 64-bit
Microsoft Access Text Driver (*.txt, *.csv) 64-bit
SQL Server Native Client 11.0 64-bit
PostgreSQL ANSI(x64) 64-bit
PostgreSQL Unicode(x64) 64-bit
ODBC Driver 13 for SQL Server 64-bit
Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx) 64-bit
...
Incompatible 32/64 bit architectures: Whatever ODBC driver you connect to must maintain same bit architecture as your MS Office version. If you run 32-bit Office, only 32-bit drivers are available (indicated under platform in step 1 output). Similarly goes for 64-bit. To verify which Office bit version you have installed on Windows and Mac, see here.
Permissions issue: While drivers are available, they may not be accessible to current user or group at file and/or folder level. This tends to be more an issue on *Unix systems (Linux/Mac) and not Windows which requires chmod or chown handling. For Windows, adjust properties of file or folder in Explorer for read/write/execute permissions.

Do I need to install drivers to connect to remote MYSQL database from Excel 2010 via VBA?

I am trying to build an application for my team the connects to a mysql database in Excel through vba. Below is my code to connect to the mysql database but when it runs it returns the following error:
[Microsoft ODBC Driver Manager] Data source name not found and no default driver specified
Do I need to install the mysql drivers in order to attach to the db? I was hoping that I wouldn't have to have everyone install them for this to work.
Is there another way or is something wrong with my connection string?
' Create a connection object.
Dim cnFEYS As ADODB.Connection
Set cnFEYS = New ADODB.Connection
' Provide the connection string.
Dim strConn As String
'Use the SQL Server OLE DB Provider.
'strConn = "PROVIDER=MySQLProv;"
'Use the MYSQL Driver.
strConn = "DRIVER={MySQL ODBC 5.1 Driver};"
'Connect to the database on abc123.
strConn = strConn & "SERVER=abc123; DATABASE=db123;"
'Use an integrated login.
strConn = strConn & " USER=user; PASSWORD=hello; OPTION=3"
'Now open the connection.
cnFEYS.Open strConn

excel vba mysql ado connection

I'm trying to establish an ADO connection between excel on my local machine and a MySQL database on my server.
In the examples I've seen (here and here, for instance) there's a driver of the form MySQL ODBC 5.x Driver. It seems that after installing the latest mysql connector / odbc download (32-bit, to match my msexcel) the relevant registry driver files HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Driver\ are now named 'SQL Server' and 'SQL Server Native Client 11.0.' I'm not having success establishing a connection to MySQL with either of these.
My VBA
Sub connect()
Dim Password As String
Dim SQLStr As String
Dim Server_Name As String
Dim User_ID As String
Dim Database_Name As String
Set rs = CreateObject("ADODB.Recordset") 'EBGen-Daily
Server_Name = "184.154.225.243"
Database_Name = "*******" ' Name of database
User_ID = "********" 'id user or username
Password = "*******" 'Password
Port = "3306"
SQLStr = "SELECT * FROM *******"
Set Cn = CreateObject("ADODB.Connection")
Cn.Open "Driver={SQL Server};Server=" & _
Server_Name & ";Port=" & Port & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
rs.Open SQLStr, Cn, adOpenStatic
Upon running the above, I receive error [Microsoft][ODBC SQL Server Drive][DBNETLIB]SQL Server does not exist or access denied. The error for the 'native client 11.0' driver is Could not open a connection to SQL Server[53].
I've tested the connection parameters in MySQL workbench and all is functional. What's going on?
Check if you are using the 32 bit or the 64 bit version of Microsoft Office.
Based on the above, download and install the appropriate MySQL driver from the download link
Once the ODBC driver installation is complete, check the ODBC snap in to see the driver is listed as installed.
If you are using a 32 bit OS, then everything is 32 bit. Use Run -> odbcad32.exe -> Drivers tab.
If you are using a 64 bit OS, and Microsoft Office is 32 bit, then use c:\windows\syswow64\odbcad32.exe -> Drivers tab.
If you are using a 64 bit OS, and Microsoft Office is 64 bit, then use Run -> odbcad32.exe -> Drivers tab.
If the MySQL drivers are properly installed, they should appear as shown above
Create a System DSN using the ODBC snap in with the MySQL driver listed above and test the connection to see if it works.
Use the same parameters when you try to create an ODBC from within VBA.
Example:
Driver={MySQL ODBC 5.3 ANSI Driver};Server=localhost;Database=myDataBase;
User=myUsername;Password=myPassword;Option=3;
Once it is established that you can successfully create a connection to the MySQL server, then change the driver name in the registry (make sure to update both the registry keys) and try using the new name you give such as SQL Server.
Remember: On a x64 bit system for a x32 bit drivers:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers
A restart may be required after changing the driver name.

mysql connection string to remote server

I have access to a database on a remote mySQL server. I can read the data from my local mySQL workbench. I can also link to, and read, its tables using MS Access.
I have tried to use the following code in VB6 but are unable to establish a connection -
Set DBCon = New ADODB.Connection
DBCon.CursorLocation = adUseClient
DBCon.Open "Driver={MySQL ODBC 5.1 Driver}; Server=sherwood.unitingchurch.org.au;port=3306; Database=UCSData;User=UCS;Password=" & Pwd & ";Option=3;"
I have a copy of the mySQL database on my local computer and the VB6 program can see and use the data without problems, using the same code (but with localhost as the server).
Set DBCon = New ADODB.Connection
DBCon.CursorLocation = adUseClient
DBCon.Open "Driver={MySQL ODBC 5.1 Driver};Server=localhost; port=3306;Database=UCSData; User=UCS; Password=" & Pwd & ";Option=3;"
Any help would be appreciated.
What is the error message?
I think your problem has to do with the driver.
Which architecture(32 or 64 bits) is your Windows,Office?

MySQL query via an HTA Application

I am running into a weird situation, hoping someone here can help.
I am communicating to a MySQL database using 'MySQL ODBC 5.1 Driver', although the below code works fine when run separately on a .vbs file, when i put the same in HTA i get Error
Error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I put the same code in a .vbs file and run the VBS file via an HTA using objShell.run command still the same problem.
When the VBS file is run independently or via CMD it runs fine displaying the contents. Any ideas ?
Call Query
Sub Query
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
adOpenStatic = 3
adLockOptimistic = 3
objConnection.Open _
"Driver={MySQL ODBC 5.1 Driver};Server=[Some Address];Database=bldb;User=usr;Password=pass;"
objRecordSet.Open "SELECT * FROM Clients Where Machine Like 00000" & , _
objConnection, adOpenStatic, adLockOptimistic
Do While Not objRecordSet.EOF
Company = objRecordSet (1)
Contact = objRecordSet (2)
Phone = objRecordSet (3)
objRecordSet.MoveNext
Loop
objRecordSet.Close
objConnection.Close
Set objRecordSet=Nothing
Set objConnection=Nothing
End Sub
I was able to figure this on, the problem was the 32/64 Bit nature of HTA and the ODBC Driver.
I had installed a 64Bit ODBC driver and my HTA was running as a 32Bit Application.
Either run %Windrir%\System32\mshta.exe or install the the 32Bit Driver.
I chose to install the 32Bit variant of the MySQL ODBC Driver which resolved the problem.