MySql.Data.MySqlClient Demo
Imports System
Imports System.Data
Imports MySql.Data.MySqlClient
Module MySqlConnect
Sub Main()
Dim connString As String = "Database=Test;Data Source=localhost;User Id=root;Password=mypassword"
Dim conn As New MySqlConnection(connString)
Try
conn.Open()
Console.WriteLine("Connection Opened")
Console.WriteLine("Connection Properties")
Console.WriteLine("- ConnectionString : {0}", conn.ConnectionString)
Console.WriteLine("- Database : {0}", conn.Database)
Console.WriteLine("- DataSource : {0}", conn.DataSource)
Console.WriteLine("- ServerVersion : {0}", conn.ServerVersion)
Console.WriteLine("- State : {0}", conn.State)
Catch ex As MySqlException
' Display error
Console.WriteLine("Error: " & ex.ToString())
Finally
' Close Connection
conn.Close()
Console.WriteLine("Connection Closed")
End Try
End Sub
End Module
Related examples in the same category