954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Connecting to a Remote Database(mySQL) on LAN

I have connected VB.net and mySQL on a the same PC before, but I have no Idea how to connect VB.net to a remote PC(LAN)

I've only changed the server

This is my code. I removed some of the details, but it works on server=localhost

conn = New MySqlConnection()
        conn.ConnectionString = "server=<strong>192.168.1.4</strong>;" & _ 
                                "user id=root;" & _
                                "password=;" & _ 
                                "database=system"

        Try
            conn.Open()
            MsgBox("You have control")
            conn.Close()
        Catch ex As Exception
            MsgBox("Connection Failed")
        End Try


I have turned off firewalls from both sides, and it keeps returning "Connection Failed"

yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

are u sure its "user id" instead of "uid" ?

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 
are u sure its "user id" instead of "uid" ?


It works when this is connecting with mySQL on the same computer. But not on other computers in the same network(lan)

The program hangs for at least 30 secs then continues with the line:MsgBox("Connection Failed")

A first chance exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

well i doubt you have the permission to connect an "extern" database server as root with no password given. did u create a user account on the remote mysql server? then you should use that account. as far as i know form linux u arent allowed to connect with the root account from outside.

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 
well i doubt you have the permission to connect an "extern" database server as root with no password given. did u create a user account on the remote mysql server? then you should use that account. as far as i know form linux u arent allowed to connect with the root account from outside.


My mySQL is just a test server. The mySQL on the same computer is the same from another computer, same account: uid="root" password=""

The program hangs for at least 30 secs then continues with the line:MsgBox("Connection Failed")

A first chance exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll

I've replacedMsgBox("Connection Failed") with this

Select Case Err.Number
                Case 1041 : MsgBox("Error: Server error")
                Case 1044 : MsgBox("Error: DB Error")
                Case 1045 : MsgBox("Error: Access denied")
                Case 1049 : MsgBox("Error: DB Error - Check the DB Name")
                Case Else
                    MsgBox("Error: " & Err.Number)
            End Select


I receive this display "Error: 5"

yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

yes error 5 is the database connection. and it doesnt matter if the sql server is a testserver. mysql does not accept root connection from another machine but localhost. just create another superuser and connect as this user.

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 
yes error 5 is the database connection. and it doesnt matter if the sql server is a testserver. mysql does not accept root connection from another machine but localhost. just create another superuser and connect as this user.


I'll just create another mySQL account and use that?

yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

yes. but make sure u set on "Hosts" % (allow from all)

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

OMG Thanks GeeksbyChoice, I can't believe a stayed up all night with this.

To anyone having the same problem
1. Don't Use the default account(user="root";password="";)
2. Create an account, settings of a new account must have "Host = %"

yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

told ya :D

can u set this thread to solved please? :D

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

So i'll just hit this "Mark as Solved" link?

yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

OMG Thanks GeeksbyChoice, I can't believe a stayed up all night with this.

To anyone having the same problem 1. Don't Use the default account(user="root";password="";) 2. Create an account, settings of a new account must have "Host = %"


sir..... i created a new account on WAMP server.... then.....


i'm using this connection string

conn = New MySqlConnection("server=192.168.1.85; user id=ilearnserver; password=serverilearn; database=ilearn")


then i got an error message:

Unable to connect to any of the specified MySQL hosts.

huejiitech
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

sir..... i created a new account on WAMP server.... then.....

i'm using this connection string

conn = New MySqlConnection("server=192.168.1.85; user id=ilearnserver; password=serverilearn; database=ilearn")

then i got an error message:

Unable to connect to any of the specified MySQL hosts.

I'm sure you got your WAMP server ONLINE.

Is the 192.168.1.85 the IP of the server?If yes, check your user privileges. In this case for ilearnserver. Go to http://localhost/phpmyadmin/server_privileges.php . Check if the host is correct.

If no, check your server's IP.

yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You