How To Connect To Mysql Database In VB.NET



hello guys , i will tell you just how to connect to mysql database in vb.net . we all know that mysql is one of the bets RDBMS which means relational database management system shortly we say DBMS which means database management system . ok now first all you need to do these things
  1. you need mysql server and mysql connector
  2. you need to add the reference mysql & mysql connector

after that with this codes you can connect to the mysql database


Imports MySql.Data.MySqlClient
Public Class form1

    'Author : Mohamed Shimran
    'Blog : http://www.ultimateprogrammingtutorials.blogspot.com

    Private mysql_connect As New MySqlConnection
    Private Sub connect_mysql()
        Dim db_name As String = "Database Name"
        Dim db_host As String = "Database Host"
        Dim username As String = "Database Username"
        Dim password As String = "Database Password"


        If Not mysql_connect Is Nothing Then mysql_connect.Close()
        mysql_connect.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", db_host, username, password, db_name)

        Try
            mysql_connect.Open()
        Catch ex As MySqlException
            MsgBox("Connecting To Database Error:[" & ex.Message & "]")
        End Try
    End Sub
End Class


replace Database Name with your database name
replace Database Host with your database host
replace Database Username with your mysql database username
replace Database Password with your mysql database password

now debug your program if you didn't get any errors your successfully connected to your database.

Post a Comment

Note: Only a member of this blog may post a comment.