Thursday, July 9, 2009

Microsoft .NET Code Generation Error with MySQL

Sometimes in tech you're forced to combine technologies that don't always seem naturally well-matched. This is especially true when you're hosting company offers one database technology, but not another, and when the natural scripting language partner to that database is slower than than the other competing language. So that brings me to running a MySQL database with ASP.NET 2.0/3.0 running the front end. Creating a simple web-based database application is pretty trivial, but even in those cases you can run into issues with unclear solutions.
        As I was putting together a simple web application with asp.net and mysql, I ran into a mysterious and misleading error that went something like:
Failed to generate code. Exception of type 'System.Data.Design.InternalException' was thrown.

        Oddly enough, the error pointed to the first line of my DAL DataSet.xsd where the XML declaration resides. It turns out, this is not a parsing error at all, but rather an issue with the .NET compiler being unable to auto-generate the C# code from the DataSet's XML. The reason being, it couldn't find the appropriate DbProviderFactory. The solution was pretty simple in the end. All I had to do was add the following SQL DB Provider to my web.config and I was on my way.


<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net
Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory,
MySql.Data, Version=6.0.4.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D" />
</DbProviderFactories>
</system.data>

No comments:

Post a Comment