4 Replies - 14349 Views - Last Post: 03 June 2009 - 09:32 PM Rate Topic: -----

#1 MarcTheOnly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-March 09

[vb.net] MySql Data + Login form [ How can the client computer read my

Post icon  Posted 03 June 2009 - 07:23 PM

First of all, Hi everyone I am from another vb.net forum so that why I have no post here.. Well I am working a kind a biggy chat server program with login form reading MySql database. Well the code below show what Ive done so far... Everything working good in the code but the login form can only read database from my computer itself...If I would try it from another friend computer it would not be able to read my data on MySql. So The thing I want is to give this code a function to make others able to read My Database by conection on my WAN IP. Ive tryed to imports Imports System.Net.Sockets but doesnt seem to work at all..Anyway Im wondering if someone advanced would Help me cause I kinda need to have this livechat done for Private server..I have a good knowledge of VB..I master alot of function but I barely phail when its come with networking..Well Take a look at the code and try help me

Thanks to all readers ~
Marc


Imports MySql.Data.MySqlClient
Imports System.Net.Sockets
Public Class Form1
	Const AppName = "Marky's Livechat System"
	Dim clientSocket As New System.Net.Sockets.TcpClient()

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		txtUserName.Focus()
	End Sub

	Private Sub cmdAuthenticate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAuthenticate.Click
		If txtUserName.Text = "" Or txtPassword.Text = "" Then
			MessageBox.Show("Please enter the required information to login.", AppName, MessageBoxButtons.OK, MessageBoxIcon.Information)
		Else
			Dim mMySQLConnectionString As String = "Server=localhost;Database=logindata;Uid=root;password =root"
			'You will need to change the connection string above to yours

			Dim conn As MySqlConnection
			Dim dr As MySqlDataReader
			Dim cmd As New MySqlCommand

			conn = New MySqlConnection()
			conn.ConnectionString = mMySQLConnectionString

			Try
				conn.Open() 'Always a good idea to open the connection in a try/catch block

				'Before you were selecting the username and password..
				'I changed that to the Status field being that its the field we need.

				cmd.CommandText = "SELECT Status FROM members WHERE UserName = ?UserName AND Password = ?Password"
				cmd.Parameters.Add(New MySqlParameter("?UserName", txtUserName.Text))
				cmd.Parameters.Add(New MySqlParameter("?Password", txtPassword.Text))
				cmd.Connection = conn
				dr = cmd.ExecuteReader

				If dr.HasRows() Then
					Form2.Show()
					Me.Close()


					'I used a datareader to hold the result of the Select Statement
					'which will be the status field if the username AND password are CORRECT

					'If they UserName and Password are wrong, the datareader will not hold any rows.

					dr.Read()

					Select Case UCase(dr(0).ToString)

						Case Is = "ADMIN"

							Dim F2 As New Form2
							F2.Show()
							Me.Close()
						Case Is = "MOD"

							Dim F3 As New Form3
							F3.Show()
							Me.Close()
						Case Is = "USER"

							Dim F3 As New Form3
							F3.Show()
							Me.Close()
					End Select

				Else
					MsgBox("Either the User Name or Password are Incorrect. Please try again.", MsgBoxStyle.Information, AppName)
					txtPassword.ResetText()
					txtUserName.ResetText()
					txtUserName.Focus()
				End If

			Catch myerror As MySqlException
				MessageBox.Show("Database Error: " & myerror.Message, AppName, MessageBoxButtons.OK, MessageBoxIcon.Information)

			Catch ex As Exception

				MessageBox.Show("Error: " & ex.Message, AppName, MessageBoxButtons.OK, MessageBoxIcon.Information)

			Finally

				'The Finally Section of a Try Catch block will always fire, even when it runs into an exception.
				'That makes it a good place to clean up 

				cmd.Parameters.Clear() 'I always clear my parameters when im done with them just to be safe
				conn.Close()

				cmd.Dispose()
				conn.Dispose()
			End Try


		End If

	End Sub

	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)


	End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: [vb.net] MySql Data + Login form [ How can the client computer read my

#2 PlanetUber  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 24
  • Joined: 03-June 09

Re: [vb.net] MySql Data + Login form [ How can the client computer read my

Posted 03 June 2009 - 07:51 PM

Just on first glance:

Is the 2nd computer / client using this same exact code? Specifically the connection string:
Dim mMySQLConnectionString As String = "Server=localhost;Database=logindata;Uid=root;password =root"


If so, then the 2nd client is trying to access the SQL DB with a server location of "localhost". I would also assume that the 2nd client does not have a copy of this DB on their computer. Maybe move the DB to an accessible location? web server?

Let me know if this helps

EDIT: Just realised that you mentioned that they need to access the DB via your WAN IP. Do you mean that you have a VPN between your network and the 2nd client's network or you have a public IP address and you are using IIS or apache web server to host the DB?

This post has been edited by PlanetUber: 03 June 2009 - 07:53 PM

Was This Post Helpful? 0
  • +
  • -

#3 MarcTheOnly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-March 09

Re: [vb.net] MySql Data + Login form [ How can the client computer read my

Posted 03 June 2009 - 07:56 PM

View PostPlanetUber, on 3 Jun, 2009 - 06:51 PM, said:

Just on first glance:

Is the 2nd computer / client using this same exact code? Specifically the connection string:
Dim mMySQLConnectionString As String = "Server=localhost;Database=logindata;Uid=root;password =root"


If so, then the 2nd client is trying to access the SQL DB with a server location of "localhost". I would also assume that the 2nd client does not have a copy of this DB on their computer. Maybe move the DB to an accessible location? web server?

Let me know if this helps

EDIT: Just realised that you mentioned that they need to access the DB via your WAN IP. Do you mean that you have a VPN between your network and the 2nd client's network or you have a public IP address and you are using IIS or apache web server to host the DB?


Yea I tryed to host it on a web serber Mysql PhpAdmin But I could not test It and I think I wouldnt have worked..But yea I Ill retry it and Ill change the LocalHost since localhost is only for local hosting but yea Ill change localhost to my WAN IP adress?
Was This Post Helpful? 0
  • +
  • -

#4 PlanetUber  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 24
  • Joined: 03-June 09

Re: [vb.net] MySql Data + Login form [ How can the client computer read my

Posted 03 June 2009 - 08:08 PM

Yeah, if the 2 clients are using same application code then yes, you will have to specify the server address. Also, keep in mind that this IP address could possibly change, so perhaps adding functionality to specify the server when logging in.

Changing localhost to the WAN IP address should do the trick. Also, you need to specify the Database path and database name. The path will be relative to the root of the initial server address.

eg.
Dim mMySQLConnectionString As String = "Server=192.168.1.200;Database=folder/logindata;Uid=root;password =root"

Was This Post Helpful? 0
  • +
  • -

#5 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: [vb.net] MySql Data + Login form [ How can the client computer read my

Posted 03 June 2009 - 09:32 PM

try this:
 Dim strCon As New MySqlConnectionStringBuilder
			Dim con As New MySqlConnection
			strCon.Server = "Localhost"
			strCon.Port = 3306
			strCon.UserID = "root" 'or any user that you created
			strCon.Password = ""  'or password you enterd
			strCon.Database = "myDB" 'database name
			con.ConnectionString = strCon.ConnectionString
			con.Open()

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1