VB.NET to MySQL Database Connection

Discuss MySQL database optimizations techniques and designing practice. Share your experience with various versions of MySQL and their performances. Ask your questions from Experts on our forum.

VB.NET to MySQL Database Connection

Postby skmale on Fri Nov 21, 2008 4:14 pm

VB.NET to MySQL Database Connection:
VB.NET is one of the most famous programming language. It's because .NET have a many feature and make programming more easy. In general, SQL Server is the database server that usualy used by user to store their data. But we can use another database that we can use. In this case, we will use MySQL. MySQL is one of database engine that used by many people in the world.

To make connection from VB.NET into MySQL we must do the following thing :
1. Download MySQL database engine from http://dev.mysql.com/downloads/

2. Install the MySQL

3. After that, you must download the connector from VB.NET into MySQL from www.mysql.com/products/connector/net

4. To use the connector, just Import the reference of MySQL DotNet Connector from Project->Add Reference

5. Make one module to do a connection into MySQL


Imports MySql.Data.MySqlClient

Module Connect
Public conn As New MySqlConnection

Public Sub ConnectDatabase()

Try
If conn.State = ConnectionState.Closed Then
conn.ConnectionString = "DATABASE=" & your database &";" _
& "SERVER=" & your host & ";user id=" & your username _
& ";password=" & your password & ";port=" & Your MySQL Port (3306) & ";charset=utf8"

conn.Open()
End If

Catch myerror As Exception
MsgBox("Connection Error")
End
End Try
End Sub

Public Sub DisconnectDatabase()
Try
conn.Close()
Catch myerror As MySql.Data.MySqlClient.MySqlException

End Try
End Sub
End Module

6. To connect to MySQL, just call the ConnectDatabase() from your form_load event
Thanks & Regards,

Sandeep Kumar Male
Assistant Programmer
skmale
 
Posts: 0
Joined: Wed Jul 16, 2008 2:31 pm
Location: Delhi-110092, INDIA.

Re: VB.NET to MySQL Database Connection

Postby qaguy08 on Thu Feb 19, 2009 4:56 pm

Thanks for sharing useful information.
qaguy08
 
Posts: 0
Joined: Wed Dec 10, 2008 2:59 pm


Return to MySQL Database

Who is online

Users browsing this forum: No registered users and 1 guest

cron