I got a hosting plan from GKG.net and I have a VB6 connection string to remotely reach MySQL database in it. I followed all instructions and tutorials about how to reach MySQL server remotely. Everything was fine till i get an error that says:
[MySQL][ODBC 3.51 Driver] Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10060)
I searched for a solution over the net for hours but still there is nothing makes sense about it.. I double checked my connections.. I can ping to my static ip, but cant reach the MySQL server in it.
From CPanel i can reach my db with phpMyAdmin. I tested my db and there was nothing wrong with it. Everything seems right. Except i still get the error message with VB6
My connection string:
Dim conn As ADODB.Connection
Dim constr As String
Private Sub OpenServer()
Set conn = New ADODB.Connection
constr = "Driver={MySQL ODBC 3.51 Driver};" & _
"PORT=" & db_port & ";" & _
"SERVER=" & db_server & ";" & _
"DATABASE=" & db_name & ";" & _
"UID=" & db_user & ";" & _
"PWD=" & db_pass & ";" & _
"OPTION=3;" & _
"STMT=;"
conn.Open constr
End Sub
So how can i resolve this damned connection issue? and
What are the odds that causes this?
Hosts where you access their database server very rarely allow remote access to the database from outside their hosting environment (I have never seen it).
If you setup the MySql database yourself (on a dedicated or virtual server plan) then you should be able to set it up to accept remote hosts. In that case you need to modify your my.con file to allow remote hosts (you can also do it via the MySql Admin tools) and you need to grant the login you are trying to use access from the remote IP:
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
Your previous comment about SQLyog is a very good idea. And I can vouch for that product. It is a great tool. The free admin tools from MySql (Workbench - http://www.mysql.com/downloads/workbench/) are also decent and will allow you to test remote access as well.
check this Solution to Connecting remotely when you get Error 10060
http://forums.mysql.com/read.php?34,49742,239961
http://www.bigresource.com/VB-Remote-MySQL-Server-h6Z8Cbaszz.html#
MySQL is setup to handle remote connections very easily. However, you must setup MySQL to allow your users in. The other thing to do, is make sure port 3306 is open on the host. If it is not, then you can't connect to MySQL. The easiest way to do this is to...
telnet myhost 3306
If you get something back like...
,
3.23.54-log▬I_&:309i☻
then port 3306 is open and MySQL is listening.
Next, make sure your userid is setup to allow access on the MySQL server. You can do this with the mysql client software, or the mysqlcc software.
Hope this helps
I had this problem. I could connect from localhost but not from a client computer. I turned off Windows firewall (windows 8). However, no joy. I then created a new rule in firewall advanced settings and BINGO it worked. The new rule just allowed incoming connections on port 3306 on my private network.
Another approach for VB6. I use it like this in all my apps and its been working for years.
Dim StoreDB As ADODB.Connection
On Error Resume Next
Set StoreDB = New ADODB.Connection
StoreDB.Open "Driver={MySQL ODBC 3.51 Driver};Server=000.000.000.000;Port=3306;Database=yourDBName;User=Someusername;Password=Somepassword;OPTION=8;"
If Err.Number = 0 Then
[VB6 Code to execute]
Else
myErrorString = Err.Description
End If
StoreDB.Close
Set StoreDB = Nothing
As mentioned, ensure port is 3306. I have a host that uses 3307. I see no problem with your code. You probably need to sort this with the host.
Add mysqlid.exe into your windows firewall settings to access your server remotely
Related
Objective:
I'm trying to connect to a database (e.g. associated with a website hosted by goDaddy) via VBA; using MS Word. I would like to distribute the VBA code via a word template so that others can also connect to my database.
Current Understanding - Is it correct?
In order to connect to a remote mySQL database I MUST configure a ODBC Data Source using (for example) mySQL Connector/ODBC (available here)?
There seems to be a way to connect without using a DSN as suggested here.
Issue:
I have been trying to use the mySQL Connector tool and am attempting to configure it with the information I have at hand. Steps taken:
download connector tool from dev.mysql.com
Control Panel > System & Security > Administrative Tools > ODBC Data Sources 64 Bit
add host: www.mywebsite.com
add user: NameOfDataBaseUser
add pwrd: PWForUser
I get the impression that I am using the wrong credentials... I found some documentation that said a list of DataBases would be displayed if connection is successful. That suggests to me that I should be using credentials for a master user - which user would that be?
Disclaimer
I do plan to connect to an online DB via VBA, but suspect that it might be better to connect indirectly via a php web-page.
If anyone has thoughts on this (security, ease of deployment, other) please let me know, it would probably be a new question. Other disclaimer, I am highly INexperienced with databases but keen to learn - slowly ;-)
I am currently working on a project with Excel where I am successfully connecting to a remote MySQL database.
I am using the DSN-less approach and this could probably work well for you, too:
Set remoteCon = New ADODB.Connection
conStr = "DRIVER={MySQL ODBC 5.3 Unicode Driver};" & _
"SERVER=myhomepage.com;PORT=3306;DATABASE=mydb;" & _
"UID=username;PWD=secret"
remoteCon.Open conStr
remoteCon.Execute ("USE mydb;")
In order for this to work, you also have to add a reference (in VBA backend): Tools > References > Check "Microsoft ActiveX Data Objects x.x Library".
You also need to have the MySQL ODBC Driver (in my case "MySQL ODBC 5.3 Unicode Driver") installed on your computer.
Queries can then be executed like this:
Dim rs As ADODB.Recordset
Set rs = remoteCon.Execute("SELECT * FROM table")
If Not rs.BOF And Not rs.EOF Then
result = rs.GetRows
End If
How to connect VBA to a Remote mySQL DataBase using ODBC
Thanks to #EVilliger & #tobifasc for your help with this, there are many 'how to configure mySQL questions' floating around but none that solved my (larger) issue.
Basic problem - my host does NOT allow remote connections to the database, except for from a single white-listed IP (this seems fairly common).
Questions Answered:
It turns out that you do NOT need to configure the mySQL connection using the connector, however you DO NEED to have an appropriate ODBC driver installed. The connector (with the driver) can be found here: https://dev.mysql.com/downloads/connector/odbc/
I uninstalled the mySQL Connector and everything seemed to continue working, until it didn't. Conclusion don't uninstall the mySQL Connector unless you have something to replace it with.
The credentials to use can be for a database user, not some elevated user.
For anyone interested in setting up and experimenting with mySQL from VBA here is a way forward:
Download & install the drivers (see above) - if the install fails you may need to install vcredist_x64.exe
Set-up a free mySQL database, I used HelioHost: https://www.heliohost.org/ (they will also give you a domain)
Create a database & user in HelioHost cPanel
Configure remote access - use wildcard % to allow all IPs
Add user to database
Use the following code to connect...
Code from accepted answer:
Sub connect2OnlineSQL()
' Note: add referecne to Microsoft ActiveX Data Objects #.# Library
' Tools > References > (scroll down...)
Set remoteCon = New ADODB.Connection
conStr = "DRIVER={MySQL ODBC 5.3 Unicode Driver};" & _
"SERVER=something.heliohost.org;PORT=3306;DATABASE=db_name;" & _
"UID=db_user;PWD=yourPassWordHere"
remoteCon.Open conStr
remoteCon.Execute ("USE db_name;")
End Sub
Thanks again :)
Following solution worked for me
Prerequisite:
Under Developer ->Tools->Reference Add the relevant Plug in for Oracle
Download and install ODBC Driver version for Oracle which you are using (32bit/64 bit)
Windows search -> ODBC Data Source -> Add Oracle driver under user DSN and System DSN
Copy paste below code which I used for MySQL and change the parameter based on your requirement
Sub ConnectToDB()
dbName = InputBox("Enter DB Name")
'Connection To MySQL
Dim oConn As ADODB.Connection
Dim str As String
str = "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=localhost;DATABASE=Employeeportal;PORT=3306;UID=root;PWD=root;"
Set oConn = New ADODB.Connection
oConn.Open str
MsgBox "Connected to MySQL DB"
'Exporting result set to Excel
Dim query As String
query = "select * from " & dbName
Dim recordSet As New ADODB.recordSet
recordSet.Open query, oConn
Sheet1.Range("A1:D1").CopyFromRecordset recordSet
oConn.Close
End Sub
I know this kind of question has been repeating so many times but there are no proper answer for it.
As a summary, I have tried connecting to localhost and my private ip address and it works fine. I have also port forwarded the port 3306 in my router, tested the external ip port (which is successfully opened).
The connection wont work if I use my public ip address for the 'server' connection string.
Link below provides more detail on my issue D: Today is the 4th day I am finding a solution to this.
Similar Question Link Here
I don`t think its a network issue (if you configured port forwarding properly)
I've had similar issue connecting to the server from the wan (or the lan) and I fixed it that way:
my server was running on Linux, by default the configuration of the server permit connection only from localhost, so to fix that I've edited /etc/mysql/ my.cnf file: changed the bind-address from 127.0.0.1 to 0.0.0.0
(if the version is kind of old you have to comment the "skip-networking" command).
also (very important) i gave privilege to connect the specific database that the application need to connect, via PHPmyadmin >> choose database >> use privileges tab.
That is the code that i`m using to connect, it works perfect from the wan (via external ip) and also from the lan to the remote server.
hope it helps...
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim conn As New MySql.Data.MySqlClient.MySqlConnection
Dim myConnectionString As String
myConnectionString = "server=XX.XX.XX.XX;" _
& "uid=root;" _
& "pwd=435435;" _
& "database=Test;"
Try
conn.ConnectionString = myConnectionString
conn.Open()
Dim query As String = "SELECT name FROM Test_Table"
Dim cmd As MySqlCommand
cmd = New MySqlCommand(query, conn)
' cmd.Parameters.AddWithValue("#username", Usernametextbox.Text)
Dim userLevel As String = cmd.ExecuteScalar()
MsgBox(userLevel)
con.Close()
Catch ex As MySql.Data.MySqlClient.MySqlException
MessageBox.Show(ex.ToString)
End Try
End Sub
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.
i am using the OBDC connector to use VBA to connect to my MySQL database. It currently runs on a local webserver (localhost) but is accessible from other PCs on the network via my PC's IP address.
In my connection function I had localhost as the location but when I change it to my IP address I get an
[MySQL][ODBC 5.2 Driver] (my computer name) is not allowed to connect to this MySQL server
error.
I presume this is a security problem. Any way to fix this?
Here is my connection function:
Public Function OpenConnection() As ADODB.connection
//This function requires the "Microsoft ActiveX Data Objects" Library (Choose v2.8 from references for compatibility across Office versions)
Dim source As String, location As String, user As String, password As String
source = "MySQL"
location = "192.168.1.60"
user = "root"
password = ""
database = "database name"
mysql_driver = "MySQL ODBC 5.2 ANSI Driver"
//Build the connection string
Dim connectionString As String
connectionString = "Driver={" & mysql_driver & "};Server=" & location & ";Database=" & database & ";UID=" & user & ";PWD=" & password
//Create and open a new connection to the selected source
Set OpenConnection = New ADODB.connection
OpenConnection.CursorLocation = adUseClient
Call OpenConnection.Open(connectionString)
End Function
You need to modify the user account in MySQL. It is possible to modify the locations users are allowed to connect from and their credentials. Look at this post:
Allow all remote connections, MySQL
I have some problems with a vb.net application.
My application was perfectly working on XP, but now on my windows 7, each time I want to connect to localhost, I have a driver problem (in french, that's why I don't put it here)...
Do you know were does it come from?
My odbc driver is up to date...
Download and install Connector/.NET.
In your project, you should be able to add a reference to MySql.Data. You can then create your connection string.
Dim oMySqlConn As MySqlConnection = New MySqlConnection()
oMySqlConn.ConnectionString = "Data Source=localhost;" & _
"Database=mySQLDatabase;" & _
"User ID=myUsername;" & _
"Password=myPassword;" & _
"Command Logging=false"
oMySqlConn.Open()
localhost can be replaced with either an IP address or 'servename.com'