Using MySQL mapping.

Topics: User Discussion
Mar 22, 2009 at 7:24 PM
Edited Mar 23, 2009 at 4:16 AM

I downloaded the current contributions I think (entlibcontrib2007-09) and placed them in the Enterprise Library's bin folder, and I have access to them as a resource, but when I try to attach the mapping, my application responds:

The type 'EnterpriseLibraryContrib.Data.MySql.MySqlDatabase, EntLibContrib.Data.MySql, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null' cannot be resolved. Please verify the spelling is correct or that the full type name is provided.

I placed the reference in my web.config based upon what others have done with the SQLite mapping, but it's not worked for me, and there is no documentation for this mapping.

  <dataConfiguration defaultDatabase="TagCMSServer">
    <providerMappings>
      <add databaseType="EnterpriseLibraryContrib.Data.MySql.MySqlDatabase, EntLibContrib.Data.MySql, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="MySql.Data.MySqlClient" />
        </providerMappings>
  </dataConfiguration>
 

Any suggestions on what I'm missing, or what I should be doing?

EDIT::
For the record, I tried to use the Enterprise Library Configuration tool, and it generated this:

      <add databaseType="EntLibContrib.Data.MySql.MySqlDatabase, EntLibContrib.Data.MySql, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null"
        name="MySql.Data.MySqlClient" />

It also does not work.
Mar 24, 2009 at 2:53 AM
Edited Mar 25, 2009 at 1:22 AM
AHA! Progress. It seems a little silly, but I have two projects, one Business logic project that references the database, and a UI project that does all the front end heavy lifting. When I added the reference for the Entlib Contrib library to the UI project, it started to work. Sorta. Now it's not able to load the MySQL data classes. So I'm now poking around the solution for this new issue.

EDIT::
It seems the Entlib Contrib classes are expecting the 5.0.3.0 version of the .NET Connector. I'm running the 5.2.5.0 version. Is this a change I can make on the web.config side, or is this something I need to install separately to get working? Or do I need to rebuild the classes with this edition?

EDIT::
I rebuilt the MySql contribution, and it seems to be working okay, I just need to find out why a stored procedure with null parameters doesn't work, but I'm away from my computer so I can't report the precise error. I'm sure I'll straighten it out when I get home.

EDIT::
The error the project returns is:
The number of parameters does not match number of values for stored procedure.

This error is thrown up because the store procedure I am trying to use has no parameters. I found the error is thrown by the following routine:
protected override bool SameNumberOfParametersAndValues(DbCommand command,
                                                                object[] values)
        {
            int returnParameterCount = 1;
            int numberOfParametersToStoredProcedure = command.Parameters.Count -
                                                          returnParameterCount;
            int numberOfValuesProvidedForStoredProcedure = values.Length;
            return numberOfParametersToStoredProcedure ==
                numberOfValuesProvidedForStoredProcedure;
        }
The bug is pretty obvious to me; the routine fails because the expected value of parameters (1) doesn't match the actual number of parameters (0). So to fix the bug, I could set the 1 to 0 but I'm worried I might break something else by doing this. Any recommendations, or thoughts?
Coordinator
Mar 25, 2009 at 9:13 AM
Hello Knightsword,

I am afraid I can only offer comments as I am no expert on MySQL.

1. Firstly the referencing issue. This may be nothing other than making sure the relevant DLL's happen to be in the bin folder along with both your UI and business projects. There is no other reason unless you have a tight coupling from the UI to the EntLib dll's somewhere, but then your project would not have compiled presumably?
2. Always use the config tool.  I am surprised by the number of people who hand edit the config files for the Enterprise Library. The Enterprise libary makes robust use of reflection so it is dependant on assembly names, version numbers and public keys, things very easy to get wrong if done by hand.
3. The relationship of the EntLib to system objects and their versions is an on-going battle and a consequence of progress.  You will have updated your system libraries (by windows update usually) since the EntLib classes were last updated.  Most of the EntLib classes are built to .NET 2.0 or possibly .NET 3.0 as 3.5 has not been around all that long.  I am in the throws right now of trying to get the MS owners of the project to do a final VS2005/EntLib3.1 based release out so that I can change and recompile the whole lot to work with VS2008/EntLib4.1
4. It would seem that there is an assumption on the part of the developer that there is always a return parameter to every stored procedure no matter what?  Could this also be a version problem?  Are you using a particularly new or very old version of MySQL perhaps that may have changed the rules on this?
5. Well done for sticking with it, I have used the EntLib since its 1.1 days and have dealt with a number of niggly little problems but the benefits have always been worth it in the end.

Cheers...   Steve
Mar 25, 2009 at 1:13 PM
Thanks Steve, appreciate the input. Lemme just update where I am so far:

Right now, all my versions of the MySql Connector to .NET, MySql are the most current stable versions. From what I can tell from the developer's prior work, he/she based it on the notion that stored procedures in MySQL always return a value. Only, they don't; in fact, they never do (at least not until MySql 6.0 gets released). What makes matters worse is that while stored procedures don't have return values, stored functions in MySQL DO. So I'm tempted to think that the original implementation was built around stored functions. Which complicates things further, as I am not sure if the DbCommand is able to discern the difference between a stored function, and a stored procedure.

I personally love the EntLib myself, I've used it for about a year and a half at work. But this is a personal project, and I would like to be able to do a dual deployment in Mono on Linux and Windows systems. So, I'll just keep struggling with it. :)
Mar 26, 2009 at 3:19 AM
Edited Mar 26, 2009 at 12:47 PM
Well, my thought now is to modify the SameNumberOfParametersAndValues routine to return the values I want/know will work with MySql, or at least the version of MySql that I am using. If the original developer for the MySql mapping is reading this, any insight would be helpful. If I manage to get this working, should I supply my changes as a contribution? I am not sure if my routines will be a step in the right direction, but you good folks would know far better than I would.

EDIT::
Woohoo! The changes I made worked!
Coordinator
Apr 29, 2009 at 10:05 PM
Well done, I am glad you have a result.