vb.net 在vbnet中使用odbc连接mysql数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22937337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connect mysql database using odbc in vbnet
提问by taspai
I have a mysql database on phpmyadmin, I installed the connector 6.8.3 (http://dev.mysql.com/downloads/connector/net/) I add a reference on the driver ((c:\Program Files\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\MySql.Data.dll) and I use this connexion string : Private _connexionParams As String = "Driver={MySQL ODBC 6.8.3 UNICODE Driver};Server=localhost;Database=GestionDuPersonnel;User=test;Password=test;" (from : http://www.connectionstrings.com/mys...ctor-odbc-5-2/).
我在 phpmyadmin 上有一个 mysql 数据库,我安装了连接器 6.8.3 ( http://dev.mysql.com/downloads/connector/net/) 我在驱动程序上添加了一个引用 ((c:\Program Files\MySQL\ MySQL Connector Net 6.8.3\Assemblies\v4.5\MySql.Data.dll) 并且我使用这个连接字符串: Private _connexionParams As String = "Driver={MySQL ODBC 6.8.3 UNICODE Driver};Server=localhost;Database= GestionDuPersonnel;User=test;Password=test;”(来自:http: //www.connectionstrings.com/mys...ctor-odbc-5-2/)。
When I start my program I get this error and I don't understand why : "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
当我启动程序时出现此错误,我不明白为什么:“错误 [IM002] [Microsoft][ODBC 驱动程序管理器] 未找到数据源名称且未指定默认驱动程序”
Thanks
谢谢
采纳答案by taspai
Finally I just do this thing
最后我只做这件事
Imports System.Data.Odbc
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports MySql.Data
Imports MySql.Data.MySqlClient
Public Class Test
Public Sub Connexion()
Dim connStr As String = "SERVER=localhost;DATABASE=GestionDuPersonnel;UID=test;PASSWORD=test"
Dim connection As New MySqlConnection(connStr)
connection.Open()
End Sub
End Class
And use the connector .NET 6.8.3 : http://dev.mysql.com/downloads/connector/net/
并使用连接器 .NET 6.8.3:http: //dev.mysql.com/downloads/connector/net/
回答by jmail
sample try this:
样品试试这个:
Imports System.Data.Odbc
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim MyConString As String = "DRIVER={MySQL ODBC 6.8.3 UNICODE Driver};" +
"SERVER=localhost;" +
"DATABASE=test;" +
"UID=root;" +
"OPTION=3"
Dim MyConnection As New OdbcConnection(MyConString)
MyConnection.Open()
MsgBox(MyConnection.State.ToString)
End Sub
End Class
refer this link: http://kyokasuigetsu25.wordpress.com/2011/01/09/connecting-mysql-and-vb-net-using-odbc-driver/
请参阅此链接:http: //kyokasuigetsu25.wordpress.com/2011/01/09/connecting-mysql-and-vb-net-using-odbc-driver/

