Adding MySql.Data.MySqlClient to DBProviderFactories in ADO.NET

Today I had an opportunity to travel back in time all the way to 2005 and work with the classic ADO.NET classes in .NET. Needless to say, I'd forgotten everything about it...

The end goal was to create a control that can connect to different databases, even different types of databases, and execute the same SQL commands based on some condition. Basically it was, at last, that real-world scenario all the ASP.NET and C# books from back in the day said just might come up some day. It only took 8 years!

Anyway, my first step was to verify that I did indeed have all my data providers in the ADO.NET DbFactories, as I needed to cover SQL Server, Oracle, and MySQL. Fortunately I quickly found this old developer.com article which laid it out for me.

View full snippet on Gist.

When I ran that, I noticed that the MySql provider was missing, which was unexpected because I did have the MySql.Data assembly (which contains the MySql .Net Connector) in my project. After a bit more searching I found this helpful StackOverflow thread: ASP.NET and MySQL .Net Framework Data Provider Issues.

It reminded me that I also have to add that Provider to the system.data node in web.config, as shown here:

View full snippet on Gist.

Once I added that to my web.config, I was able to see it in the list of providers above.

Now I'm ready to rock!

Enjoyed this post and/or found it useful?
Tagged with:
SelArom Dot Net Profile Image
SelAromDotNet

Josh loves all things Microsoft and Windows, and develops solutions for Web, Desktop and Mobile using the .NET Framework, Azure, UWP and everything else in the Microsoft Stack.

His other passion is music, and in his spare time Josh spins and produces electronic music under the name DJ SelArom.



Scroll to top