VB.NET & Remote mySQL server !!

SyRiAn_BoY

New member
Joined
Sep 26, 2006
Messages
1
Programming Experience
Beginner
Hello all programmers in vbforums.com !
I have a mySQL database on my linux server.
I have VB.NET forums.
indeed i have cpanel & WHM with allow me to setup remote mysql server.
But i dont know how to setup the remote mysql server and how to connecting my vb.net forum to the mysql server on my linux server.
I tried to use MYODBC and Mysql Connector, but all my tried was failed .
Please any one explain to me the way to make mysql server and connecting vb.net with it.

OMAR, Regards :blush:
 
Firstly go to www.mysql.com and download the .NET Driver/Connector.

Add a reference to the mysql library.
Imports MySql.Data.MySqlClient at the top of your app.
Build a connection string, (I use variables to define the values)

Dim myConnString AsString = String.Format("server={0};user id={1};password={2}; database={3}; pooling=false", SQLServerStr, SQLUserStr, SQLPassStr, SQLDatabaseStr)

Dim myconn AsNew MySqlConnection(myConnString)

Then in a Try Catch Loop run your SQL statement

Try
mycommand.Connection = myconn
myconn.Open()
mycommand.CommandText = "SELECT myField FROM myTable"
dr = mycommand.ExecuteReader
While dr.Read
Me.ComboBox.Items.Add(dr.GetString(0))
EndWhile
dr.Close()
myconn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
EndTry
myconn.Close()
myconn.Dispose()

The routine above will add values to a combobox.
 
Hello all programmers in vbforums.com !
I have a mySQL database on my linux server.
I have VB.NET forums.
indeed i have cpanel & WHM with allow me to setup remote mysql server.
But i dont know how to setup the remote mysql server and how to connecting my vb.net forum to the mysql server on my linux server.
I tried to use MYODBC and Mysql Connector, but all my tried was failed .
Please any one explain to me the way to make mysql server and connecting vb.net with it.

OMAR, Regards :blush:

Is the correct port open on the server? If you cannot connect to port 3066 neither connector will connect. Is this your own server or an ISP hosted one?
 
Firstly go to www.mysql.com and download the .NET Driver/Connector.

Add a reference to the mysql library.
Imports MySql.Data.MySqlClient at the top of your app.
Build a connection string, (I use variables to define the values)

Dim myConnString AsString = String.Format("server={0};user id={1};password={2}; database={3}; pooling=false", SQLServerStr, SQLUserStr, SQLPassStr, SQLDatabaseStr)

.
.
.


Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
EndTry

Why turn off pooling?

Also you need to catch a general exception after the MySQLException as there may well be connectivity /general failures as well.
 
Back
Top