VB.Net/Database ADO.net/MySQL
Версия от 16:40, 26 мая 2010; (обсуждение)
MySQL Connection String
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
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