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
Related
I am using VB.NET to connect to a MySQL database.
I have the following code:
Public Function getListOfDatabase() As List(Of String)
Dim SQL As String = "select * from covenusers"
Dim output As New List(Of String)()
' Set the connection string in the Solutions Explorer/Properties/Settings object (double-click)
Using cn = New MySqlConnection("Server=server33.web-
hosting.com;Port=3306;Database=dbname;Uid=dbusername;
Pwd=password123;")
Using cmd = New MySqlCommand(SQL, cn)
cn.Open() 'this is where it breaks
' do stuff
End Using
End Using
Return output
End Function
I'm using Imports MySql.Data.MySqlClient for the MySQL handling. I get the exception: Unable to connect to any of the specified MySQL hosts.
I know my server address, username, database name, and password are all correct. What exactly am I connecting to here? Does it go through SSH or something else?
Apparently shared hosts do not allow you to connect to the MySQL database directly. I had to set up a SSHClient using Renci.SSHClient (google it) and port forward my database through that. What a pain smh
Hopefully this will help someone having the same issue.
I need to access data from the database and manipulate the data. I can do this through the internet, however I need to make it so that the data can be accessed on the computer that the program runs without having internet connection.
The current method I'm using is displayed below with the code:
Dim dbDataSet2 As New DataTable
Sqlconn = New MySqlConnection
Sqlconn.ConnectionString="server=xx.xx.xx;userid=root;password=xxxxxx;database=xxxxxx"
Dim SDA As New MySqlDataAdapter
Dim bSource As New BindingSource
Try
Sqlconn.Open() 'open connection
Dim query As String
query = "SELECT * FROM bbs_test.test"
command = New MySqlCommand(query, Sqlconn)
SDA.SelectCommand = command
SDA.Fill(dbDataSet2)
bSource.DataSource = dbDataSet2
DataGridView_array.DataSource = bSource
SDA.Update(dbDataSet2)
Sqlconn.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Is there a was to change this, so the file location is using a path like C: \ ...... or something similar
Also the file gets updated as well from time to time and the format of the file is .sql
Please can anyone help me
Thank You
The problem is likely the server address in the connection string. To make it connect to your local SQL Server engine, you can simply set the address to either (local) or ., for instance:
Sqlconn.ConnectionString="server=.;userid=root;password=xxxxxx;database=xxxxxx"
You can use local IP address of lan adapter or IP address of localhost (127.0.0.1) it work without internet connection because everything is on local computer.
You could use a local - physical database like Access.
https://kyokasuigetsu25.wordpress.com/2011/01/16/how-to-connect-ms-access-with-vb-net-using-oledb-2/
I am trying to connect to Mysql database through vb.net
However I run into the error:
Unable to connect to any of the specified MySQL hosts
Here is the code:
Imports MySql.Data.MySqlClient
Public Class DBProject_1
Dim MysqlConn As MySqlConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=root;database=My_Mysql_Database"
Try
MysqlConn.Open()
MessageBox.Show("Connection Successful")
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
End Class
I have even tried to use
MysqlConn.ConnectionString = "server=**127.0.0.1**;userid=root;password=root;database=My_Mysql_Database"
This may be the reason:
When I test connection of the Mysql database in Mysql Workbench the test fails.
The error is Failed to Connect to Mysql at 127.0.0.1:3306 with user root
Try with this ConnectionString:
MysqlConn.ConnectionString = "Server=localhost;Database=My_Mysql_Database;Uid=root;Pwd=root;"
The "Can't connect to MySQL server" error usually is the result of not being able to reach the server, e.g. if it is not running or it is on a remote machine but firewalls block access. See also the video I added to the MySQL channel for how to set up connections.
Please check that MySql Service is running by typing "services.msc" in the "run".
I hope it will help you!
I have the same problem.
But I was a server, in a domain, and now the server is outside the domain.
I try to change the rulesin firewall of the server (where there is MySql server).
So go to inbound rules, and search the 2 Mysql rules.
Open them and search th Advanced item.
Then check Domain, or/and Private, or/and Public
(for me, Domain was the only cheked option, not good for me because I 'm now outside the domain).
Hope it helps !
Cheers :)
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
I am using Visual Studio 2010. I can connect to my MySQL datababse no problem by clicking my login button.
Now I can't figure out how to query the database and check if username and password are correct, and switch to a different form, to display the data loaded from the database.
Can Anyone Help?? Please
I should have posted my Code
This is Login.vb Form
Imports MySql.Data.MySqlClient
Public Class Login
Dim conn As MySqlConnection
Private Sub Login_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login_btn.Click
conn = New MySqlConnection
conn.ConnectionString = "server=localhost;user id=root;password=johnny;database=test"
Try
conn.Open()
If conn.State = ConnectionState.Open Then
connectionstatus.Text = "Connected to Database"
conn.Close()
End If
Catch myerror As MySqlException
connectionstatus.Text = "Unable to Connect to Database"
Finally
conn.Dispose()
End Try
End Sub
End Class
When the login is completed, and username and password are correct, I want it to load Main.vb.
follow the following article, it explains how to create the login form using mysql and vb
http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-3
What you need is to create a sql command that will find a record in the database table that match the username and password values. So something like
SELECT username, pwd FROM tblUsers WHERE username = #username and pwd = #pwd
You will need to pass the username and password as parameters... do not pass the textbox values directly as you will be open to Sql injection. Execute the command if you get a row then the user exists and their password was correct. You should encrypt the password and only store the encrypted password in the database...
Look for tutorials on how to query database once you connect to it.
you should never post your mysql information inside of any program - instead try having it connect via php - that way your mysql information is secure