Access to mysql database from other computer(VB.net/Mysql)

shohoku

Active member
Joined
Jun 15, 2005
Messages
31
Programming Experience
Beginner
i'm using vb.net and mysql as database
and the linking btm them is using the myodbc
now my database setting up in computer A
and i have a login program in computer B
how can i link my login program from com B to comA's database:confused:
thanks and sorry for my lousy sentence...
hope u guys can understand what i means:)
 
The mysql server will need a user created that has access from other computers or the computer where the client is located. Now the client program can either use the servers computer name or IP address to connect to the mysql server, I prefer the IP.

Chester
 
Have you downloaded the .net connector or ODBC? I prefer the .net connector for mysql. You can find it here http://dev.mysql.com/downloads/connector/net/1.0.html.

And this link will descirbe how to connect using the connector http://www.vbmysql.com/articles/vb_mysql_tutorials/vb_mysql_tutorial-part3.html

And particular information about setting up your connection here:
http://www.vbmysql.com/articles/vb_mysql_tutorials/vb_mysql_tutorial-part3.html#part18

That is a very good tutorial on mysql and vb .net.

Hope that helps.
Chester
 
The methods will be a little different. ODBC is older than the connector. The .net connector is not to big of a download and ODBC will probably one of these days go away.

Chester
 
i think i make some mistake...
what i want is not login to the whole mysql server
for example i have a database name:SEAS
inside has a table(Empdatail) in the table has two fields(ID, password)
now in client side the user want to login to sys based on ID and password
when user keyin ID,password and click login
the id and password will be send to compare. if correct than user can login...
 
VB.NET:
Dim myCommand As New MySqlCommand("SELECT COUNT(*) FROM Users WHERE UserName = @UserName AND Password = @Password", <your connection here>)

 myCommand.Parameters.Add("@UserName", MySqlType.VarChar).Value = Me.userNameText.Text
 myCommand.Parameters.Add("@Password", MySqlType.VarChar).Value = Me.passwordText.Text

If CInt(myCommand.ExecuteScalar()) = 0
	MessageBox.Show("Login failed.")
Else
	MessageBox.Show("Login successful.")
End If
 
hi~~
can i ask u what the <your connection here> i should put?

isi it below connection??

"DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=localhost;" & _
"DATABASE=seas;" & _
"UID=root;" & _
"PASSWORD=;" & _
"OPTION=3;"
 
What you have there is the connection string. You create a new connection by either providing the connection string to the constructor or setting the ConnectString property:
VB.NET:
Dim myConnection As New MySqlConnection(<your connection string here>)
or
VB.NET:
Dim myConnection As MySqlConnection

myConnection.ConnectionString = <your connection string here>
Note also that ExecuteScalar requires an open connection. That means you will have to explicitly call Open on the connection before calling ExecuteScalar, and then call Close afterwards.
 
is it correct??
but when i run it
it come out some error
=>> "If CInt(myCommand.ExecuteScalar()) = 0 Then"
VB.NET:
		Dim myData As New DataSet
		Dim SQL As String
		Dim myAdapter As OdbcDataAdapter
		Dim conn As OdbcConnection
		Dim acc As Data.DataRow
		Dim a As OdbcCommandBuilder

		conn = New OdbcConnection
		conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
					   "SERVER=localhost;" & _
					   "DATABASE=seas;" & _
					   "UID=root;" & _
					   "PASSWORD=;" & _
					   "OPTION=3;"

		Dim myCommand As New OdbcCommand("SELECT COUNT(*) FROM empdetail WHERE Employee_ID = @ID AND Epass = @Password", conn)

		myCommand.Parameters.Add("@ID", OdbcType.VarChar).Value = Me.TextBox1.Text
		myCommand.Parameters.Add("@Password", OdbcType.VarChar).Value = Me.TextBox2.Text

		If CInt(myCommand.ExecuteScalar()) = 0 Then
			MessageBox.Show("Login failed.")
		Else
			MessageBox.Show("Login successful.")
		End If
 
As I said in my previous post, ExecuteScalar requires an open connection. You have to call conn.Open() beforehand and conn.Close() afterwards.

Also, if ever you are asking for help on an exception in future, please include details of the exception itself, i.e. type and error message. I knew what this one was straight off but it is often not possible to know what caused the exception without knowing what exception was caused.
 
okok...
next time i will remember to put the error message..
i have a new problem...
when i add in the conn.open and conn close
is no problem in "If CInt(myCommand.ExecuteScalar()) = 0 Then"
but when i run and type correct id and password to login
it still shows
"Login Fail."

thanks for ur help...
 
Back
Top