Home > Software design >  using OleDbConnection with mysql server
using OleDbConnection with mysql server

Time:04-14

So I just migrated an Access Database to a MySql Database. I wan't to know if it's possible to use the OleDbConnection with MySql server.

Here's what I want to use :
New OleDbConnection(Provider=WHAT_HERE;Data Source=127.0.0.1,3306;Initial Catalog=*****;User ID=*****;Password=****)

I know that there is MySqlConnection, but since this is a big, old project, I don't want to re-do all the coding.

CodePudding user response:

I would strongly suggest that you switch to MySqlClient instead of OleDEb. It's really not a big deal to do so. Hopefully you have imported the System.Data.OleDb namespace at the project level, so you could just remove that import and every usage of an OleDb type will be flagged. You can basically use Find & Replace to change all the OleDb types to MySqlClient, e.g. find OleDbConnection and replace with MySqlConnection.

There is no first-party OLE DB provider for MySQL. There may be third-party options but I'm not aware of any specifically. There is the Microsoft OLE DB Provider for ODBC Drivers, so you could use that to connect to the MySQL ODBC driver, but that seems like a brittle solution to me.

Given that converting to MySqlClient is not especially onerous, I'd stick with that. One gotcha that you might want to be careful of is that, if you don't have Option Strict On (which you ABSOLUTLEY should) then there may be instances where creation of a MySqlParametrer will accept an OleDbType without a compilation error but will behave incorrectly at run-time. Be sure to find ALL instance of the characters "oledb" in code.

  • Related