I have the following code to connect the localhost database with OLEDB using VB.NET. Below are the code:
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
When running, the error "The 'MySQLProv' provider is not registered on the local machine." appears. I already installed MySQL Connector Net 6.5.7 and MySQL Connector ODBC 5.3 but Visual Studios says it is not installed.
I also have tried different connection string as below but each of them has error:
'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;"
I also done referencing Mysql.Data in my project.
**I do not want to use MySQL Client.
Please help. Thanks
There are three connection strings for MySQL using OLEDB as stated here :
Standard
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
MySQL
Specifying TCP port
Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;
The port 3306 is the default MySql port.The value is ignored if Unix socket is used.
Multiple servers
Use this to connect to a server in a replicated server configuration without concern on which server to use.
Server=serverAddress1, serverAddress2, serverAddress3;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
使用“provider = MSDataShape”解决
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.