我有以下代码使用VB.NET连接localhost数据库和OLEDB。以下是代码:
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Module Module1
Public conn As OleDbConnection
Public Sub OpenConnection()
conn = New OleDbConnection()
If conn.State = ConnectionState.Closed Then
Try
conn.ConnectionString = "provider=MySQLProv; Data Source=mydbname; User Id=root; Password=password"
conn.Open()
MsgBox("Connected to DB")
Catch ex As OleDbException
MessageBox.Show("Error Connecting to Database")
conn.Close()
conn.Dispose()
End Try
End If
End Sub
运行时,错误" MySQLProv'提供商未在本地计算机上注册。"出现。我已经安装了MySQL Connector Net 6.5.7和MySQL Connector ODBC 5.3,但Visual Studios表示它没有安装。
我也尝试过不同的连接字符串,但每个连接字符串都有错误:
'conn.ConnectionString = "Driver={MySQL};SERVER=localhost;DATABASE=smsengine5;USER=root;PASSWORD=password"
'conn.ConnectionString = "provider=MYSQLOLEDB; Driver={MySQL};SERVER=localhost;DATABASE=mydbname;USER=root;PASSWORD=password"
'conn.ConnectionString = "provider=.NET Framework Data Provider for MySQL;*;Uid=root;Pwd=password;Database=mydbname;"
'conn.ConnectionString = "provider=MySQLProv; Data Source=mydbname; User Id=root; Password=password"
'conn.ConnectionString = "Driver={mysql};Server=localhost;PORT=3306;UI D=root;PWD=password;OPTION=16386"
'conn.ConnectionString = "Provider=<<MySQLProv>>; Location=<<localhost>>; Data Source=<<mydbname>>; USER ID=<<root>>; PASSWORD=<<password>>; option=3;port=33 06;"
'conn.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost Database=mydbname; User=root; Password=password; Optio n=4;"
'conn.ConnectionString = "Provider=MySQLProv.3.9;Location=<<localhost>>;Data Source=<<mydbname>>; USER ID=<<>root>>;Password=<<password>>;port=<<3306>>;"
'conn.ConnectionString = "Provider=MySQL Provider; Data Source=localhost; User ID=root; Password=password; Initial Catalog=mydbname;"
'conn.ConnectionString = "Server=localhost;Database=mydbname;Uid=User;Pwd=mypass; providerName=MySql.Data.MySqlClient"
'conn.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=mydbname; User=root;Password=myPassword;Option=3;"
'conn.ConnectionString = "Provider=SQLOLEDB; Data Source=localhost; Initial Catalog=mydbname; User ID=root; Password=password;"
'conn.ConnectionString = "Data Source=localhost:3306;Database=mydbname;User ID=root; Password=password;"
我也在我的项目中引用了Mysql.Data。
**我不想使用MySQL客户端。
请帮忙。感谢
答案 0 :(得分:0)
使用OLEDB的MySQL有三个连接字符串,如here所述:
标准强>
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
MySQL
指定TCP端口
Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;
端口3306是默认的MySql端口。如果使用Unix套接字,则忽略该值。
多台服务器
使用此选项连接到复制服务器配置中的服务器,而无需考虑要使用的服务器。
Server=serverAddress1, serverAddress2, serverAddress3;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
答案 1 :(得分:0)
使用“provider = MSDataShape”
解决