Connect To Remote MySQL Database Using VB
Connect To Remote MySQL Database Using VB
NET 2010
Ask Question
Asked 7 years, 2 months ago
Active 3 years, 7 months ago
Viewed 31k times
2
2
My connection string as follows.
//192.248.***.***/phpmyadmin
Also i can log in to local MySQL database using:
conn.ConnectionString = "server=" & "localhost" & ";" & "user id=" & "admin" & ";" & "password=" & "" & ";" & "database=abc"
What is the wrong in this code. I want to connect to the remote database since it is the requirement of the system. Any help please.
nirosha rathnayaka
18811 gold badge55 silver badges1818 bronze badges
post your full stack trace error – Ami Dec 10 '12 at 9:18
maybe you have typo in your port .. the default port is 3306 not 3036. unless you changed it. – kiLLua Feb 3 '17 at 5:33
add a comment
5 Answers
activeoldestvotes
4
Connect to remote MySQL Database Using VB.Net
To connect vb.net to remote MySql database ; No matter what VB.Net version you might be using, just go throw the following steps.
4) Add the "Mysql.Data.dll" as a reference to your project, which you can find it in the path (C:\Program Files\MySQL\Connector Net
6.9.6\Assemblies\v4.5);
6) Create the class named "Database" and write in the following code.
With data
'Assing the object property values
.ServerName = txt_server.Text
.DatabaseName = txt_database.Text
.UserID = txt_uid.Text
.Password = txt_pwd.Text
'Connection testing
If .Connection Then
MessageBox.Show("Database Conneted.")
Else
MessageBox.Show(.ErrorMessage)
End If
End With
End Sub
Private Sub btn_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_exit.Click
Close()
End Sub
End Class
7) Run the project and try the connection; if the connection is successfully then your luck; and if the connection is not successfully with the
8) Note the ip address on error message after @ (thats your ip) and add it to your domain cpanel "remote mysql access" the image bellow
illustrates how the remote mysql access looks like(they are the same bu they may defer in colors); Don't forget to press "add hosts" button.
This settings can work daily for those who are in static
ip.
But if the error message persists try to leave the password text blank and connect again if you had no password in your remote database; if
the error comes again except YES is changed to be NO then you have to check if your in DHCP;
9) If your in DHCP which means the ip is changing in every new Internet connection. If your using modem probably your in DHCP. If your
in dynamic ips then check what is changing in the ip's 4 blocks. If the first ip was 197.250.3.201 in the first connection and the next ip is
197.250.60.70 and the next next ip is 197.250.80.24; you have to add 197.250.% in your cpanel access hosts for your connection to be
stable.
10) Note: As the percent symbol (wild card) flows to the left side of the ip address the more the door of security becomes open. On new
error please contact your domain provider there might be some other security issues in the domain. Thanks!
Simbo
4133 bronze badges
This class can be replaced by dev.mysql.com/doc/dev/connector-net/6.10/html/… – Mary Jul 17 '19 at 20:43
add a comment
1
just try this , it will work
Persist Security
in your code . to access your mysql database of your server of site . go cpanel > Remote MySQL , and add your ip address
Prappo Prince
1111 bronze badge
add a comment
0
The default port for MySQL is 3306. If you can connect from phpmyadmin using the default settings it sounds like a typo and you should
have:
http://www.debianhelp.co.uk/remotemysql.htm
For a Windows host the following may prove useful:
http://techminded.net/blog/allow-remote-connections-for-mysql-on-windows.html
shareimprove this answer
edited Dec 10 '12 at 10:10
answered Dec 10 '12 at 9:37
PeterJ
2,8871212 gold badges4242 silver badges5353 bronze badges
Also try Uid=admin; Pwd=*** - I seem to remember the MySQL connector doesn't allow some aliases that SQL/Server does – PeterJ Dec 10
'12 at 9:51
Nope. Still the same error. Is there something should I have to do since it is secured. – nirosha rathnayaka Dec 10 '12 at 9:57
Also noticed that phpadmin is on the other machine, maybe a firewall problem on the machine and port 3306 isn't open for remote
connections? Maybe install MySQL Workbench and see if you can connect remotely to isolate the problem. – PeterJ Dec 10 '12 at 9:57
Further comment, if you can't connect from MySQL Workbench then we'll need to know the operating system MySQL is running on to
solve the problem. Just about to update my answer. – PeterJ Dec 10 '12 at 10:06
Thanks Peter, I tried using MySQL WB. It says cannot connect. It shows 192.248.***.*** (10060). Is it port 10060? The OS is Win 2000
server. – nirosha rathnayaka Dec 10 '12 at 10:14
show 3 more comments
0
Iv previously had the same issue, i was the same as it was running on a different server.
Try to ping the server from where the application is running and see if you can connect. that's how i found out and needed a firewall change.
Gerry85
6122 silver badges99 bronze badges
add a comment
-1
try changing port to 3307 on .ini config of mysql then bind-address=server's ip or hostname on .ini config of mysql also