Bug #34451 mySQL Connector/NET breaks Membership Provider List.
Submitted: 10 Feb 2008 22:40 Modified: 1 Mar 2008 10:21
Reporter: Paulo Santos Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:5.2.0 OS:Microsoft Windows
Assigned to: CPU Architecture:Any
Tags: Membership Provider, Profile Provider, Roles Provider

[10 Feb 2008 22:40] Paulo Santos
After installing the Connector on a machine whitout the mySQL installed the membership provider system on installed websites break.

The problem is caused by the fact that the connection string on the machine.config that the setup process updates is empty, because the machine in question does not have mYSQL installed.

======== Error message ========

Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: Error during provider initialization.

Source Error: 

Line 146:        <add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />

How to repeat:
On a machine without mySQL install the mySQL Connector/NET and access any website hostaed by the refered machine that uses the Membership Provider system.

Suggested fix:
There are two possible solutions:

1. Change the setup to ask for the desired mySQL box and update the connection string accordingly

2. Patch the initialization procedure on MySQLMemebershipProvider.Initialize, MySQLProfileProvider.Initialize and MySQLRoleProvider.Initialize to exit after checking if the connection string is empty.
[14 Feb 2008 20:14] Reggie Burnett
I don't understand the problem here.  The installer creates a dummy connection string simply because the provider registrations reference one and if there isn't one there you get an error.

The connecton string should always be overridden in your web.config which goes with your web app so if the connection string is blank, that is a problem with your app, not the provider.
[14 Feb 2008 22:41] Paulo Santos
The problem is precisely this.

The installation procedure updates the MACHINE.CONFIG. That is the configuration for the whole machine.

Imagine that I'm a ISP offering an ASP.NET connection to an mySQL database and install the mySQL Connector/NET to offer my clients this service.

Also imagine that I have 1000+ websites running on the server that does not use a mySQL database.

So after I install the mySQL Connector/NET all those 1000+ websites start to crash because the damn connector throws an exception because it demands the connection string there.

I'd have 1000+ less clients on my server because they would be pissed of at me and would not give a damn about whose fault it is.

To wrap this out, this is a HUGE bug to demand a connection string present on the machine.config.
[15 Feb 2008 4:23] Reggie Burnett
I'm sorry but I still fail to see the problem.  The connection string is named LocalMySqlServer and that name means something only to the providers.  If your 1000 clients are not using MySQL then they won't be using our providers and therefore will not be affected by the connection string.

Here is the reason that connectoin string is there.  We register our providers in machine.config the same way that SqlClient does.  We register reasonable defaults and one of those defaults is the name of a connection string.  The idea here is that if you take the defaults then you can use membership, roles, or profiles in your app without having to re-register the provider.  You would simply need to define a connection string named LocalMySqlServer and specify that you want to use the MySQLMembershipProvider (for example).  If we didn't link the connectoin string to the provider in machine.config, then the user would have to do that in their web.config which is an unnecessary headache.  Also, if we register the provider and reference a connection string that is not there, then every website is affected.  That is considered a sytnax error in machine.config and no site would work.  They work precisely because we default the connection string.

I"m more than willing to be proven wrong on this and will fix it if that turns out to be the case but right now I don't see the problem.
[15 Feb 2008 7:27] Paulo Santos
Reggie Burnett wrote:

"Also, if we register the provider and reference a connection string that is not there, then every website is affected. That is considered a sytnax error in machine.config and no site would work."

And that is precisely the point. In the scenario that I described the problem is when you install the mySQL Connector/NET on a machine that DOES NOT have mySQL installed locally.

By default the ASP.NET combines the providers from the machine.config with the providers on the web.config. When a website attempts to access the Membership class for the first time the ASP.NET initialize the entire collection, that is, the providers on the web.config AND on the MACHINE.CONFIG.

Because the box does not have the mySQL installed (it is installed on another machine) the installation procedure defaults an empty string which causes the error on every freaking website, that uses the Membership class, hosted on the server.

As I stated on the bug description I see two possible solutions:

1. Fix the installation procedure to ask for the desired server in case no mySQL is found on the current box; or

2. Fix the mySQL Connector/NET in a way that it does not attempt to connect to the mySQL database on its initialization procedure.
[15 Feb 2008 7:34] Paulo Santos
There is a workaround as I posted on my blog (http://pjondevelopment.50webs.com/blog/2008/02/workaround-to-mysql-connectornet-bug.html).

But it requires changing every website installed on the machine.

I'm not saying that the installation should not change the machine config, I'm saying that it should work with its own defaults.

If there is no mySQL on the computer where the mySQL Connector/NET is being installed it should ask for where to point the default database.
[22 Feb 2008 17:54] Reggie Burnett
This is now verified.  I didn't realize (but should have) that all the providers listed in machine.config would be initialized when the web admin is shown.
[22 Feb 2008 17:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

[22 Feb 2008 17:58] Reggie Burnett
Fixed in 5.2.1
[1 Mar 2008 10:21] MC Brown
A note has been added to the 5.2.1 changelog: 

When using web providers, the Connector/NET would check the schema and cache the application id, even when the connection string had been set. The effect would be to break the memvership provider list.