VB.NET Tutorial : How to create connection to Remote MySQL Database Server using TCP/IP Client and Server, How to Set up a remote MySQL database connection.
Connection to Remote MySQL Database - How to create a connection from a client Pc to a server database that in one Network? The database server is at 192.168.5.99 and the port number is 3306, Pc client have an ip 192.168.5.101, so the client and the server is at one Networking Area.
Please read :
Click on your Database > Privileges > and Add user account > OK
Open your httpd.conf using notepad or other text editor, find this line "LoadModule vhost_alias_module modules/mod_vhost_alias.so", then remove the "#" characters and save it.
Open your httpd-xampp.conf.
At the last line, add this following command :
Source Code Connection TCP (Form1.vb)
Download Full Source code here
see you next lessons.
Please read :
- Multi Client Server Chat Application TCP/IP Client/Server MultiThreaded
- Client Server Chat Application TCP/IP Client/Server for One Client
How to Enable Remote Access To MySQL Database Server?
To can anyone to remote server database, we must setting up database server and the server (xampp) that can romoted by any client,1. Setting Server Database
at your server, open following this URL : http://localhost:8080/phpmyadminClick on your Database > Privileges > and Add user account > OK
2. Setting Xampp Server
at the server PC, open your Xampp Control Panel > Config (Apache) > httpd.confOpen your httpd.conf using notepad or other text editor, find this line "LoadModule vhost_alias_module modules/mod_vhost_alias.so", then remove the "#" characters and save it.
Open your httpd-xampp.conf.
At the last line, add this following command :
Allow from all is using to allow all client connect with our server.AllowOverride AuthConfig Allow from all Require local ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
Create Connection to Remote MySQL Server
Open your visual studio and we will create new project "ConnectionTCP", and at the form1.vb add one comboBox, button and one label, just design it look like thisModule Connection (moduleConnection.vb)
Imports MySql.Data.MySqlClient ' we will make connection using ADO.NET
Module ModuleConnection
Public conn As MySqlConnection ' declare our connection
Sub openConnection()
Dim server As String = "192.168.5.99" ' our server database
Dim userID As String = "root" ' Server userid
Dim password As String = "rahasia" ' server password
'Dim databases As String = "" 'server database, i have a database, but dor this project we will
' not use the database
Try
Dim query As String = "Server=" & server & "; user id=" & userID & "; password=" & password & "; Convert Zero Datetime=True"
conn = New MySqlConnection(query)
If conn.State = ConnectionState.Closed Then
conn.Open() ' open our connection
MsgBox("Connection Success !")
End If
Catch ex As Exception
MsgBox("connection filed !")
End Try
End Sub
End Module
Source Code Connection TCP (Form1.vb)
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
openConnection() ' open our connection
' query to show all database from our server
Dim cmd As String = "SELECT DISTINCT TABLE_SCHEMA FROM information_schema.TABLES"
Dim da As MySqlDataAdapter = New MySqlDataAdapter(cmd, conn)
Dim dt As New DataTable ' we will use datatabel
da.Fill(dt)
' enabling the list of database in the combobox
ComboBox1.Enabled = True
ComboBox1.Items.Clear()
ComboBox1.Items.Add("== Select LIST Database ==")
Dim i As Integer = 0
While i < dt.Rows.Count
' add database list into combobox
ComboBox1.Items.Add(dt.Rows(i)(0).ToString())
i = i + 1
End While
ComboBox1.SelectedIndex = 0
conn.Clone()
dt.Dispose()
da.Dispose()
Catch ex As Exception
MsgBox("Failed to connect with database server")
End Try
End Sub
End Class
Informations :
You can create CRUD Operations using Remote MySQL Database above, just configuration your server database and create connection to your CRUD Project, see crud Project here :- VB.NET SQLite Tutorials : CRUD (add,update,delete) Operations ADO.NET
- GridView CRUD Operations in VB.NET using ADO.NET and MySQL Database
- CRUD (Create,Read,Update,Delete) Operation Ms Access Database OleDB Connection
- VB.NET (Create,Read,Update,Delete) Database SQL Server
Video Tutorial Connecting to Remote MySQL Server
Download Full Source code here
see you next lessons.
COMMENTS