0

I have a class derived from SqlMembershipProvider with a function Initialize that overrides the original. This function is not being called.

I am using Microsoft membership services. I need to use a dynamically defined connection string. I need to provide an alternative Initialization routine. I define a class and replacement routine but it is never called.

Here is the code:

namespace MyNameSpace
{
    public class MySqlMembershipProvider : SqlMembershipProvider
    {
        public override void Initialize(string name, NameValueCollection 
           config)
        {

            config["connectionStringName"] = 
                 cearDBUtilV10.adminMgt.adminConnString;
            base.Initialize(name, config);
        }
    }
}

Here is the app.config file:

<membership defaultProvider="MySqlMembershipProvider">
<providers>
<clear />
<remove name="cearDBUtiulV10.Properties.Settings.cear_admin" />
<add name="MySqlMembershipProvider" type= />
</providers>
</membership>
<connectionStrings>
<add name="xxxxEntities" 
connectionString="string" />

<add name="cearDBUtilV10.Properties.
           Settings.cear_adminConnectionString"
           connectionString="conn string" />
</connectionStrings>
Fildor
  • 14,510
  • 4
  • 35
  • 67
odbdux
  • 43
  • 9
  • @Fildor - the Code should compile just fine the method is declared virtual in the base class - https://learn.microsoft.com/en-us/dotnet/api/system.configuration.provider.providerbase.initialize - if you are wondering if you can override an already overriden method thats possible as you can see here in that example: https://dotnetfiddle.net/XjCiXN – Rand Random Jun 18 '19 at 11:16
  • @RandRandom I worded badly, sorry. You can override, but it will not behave as expected (by OP). – Fildor Jun 18 '19 at 11:21
  • No, wait ... it actually _should_. Could the missing type in `` be a cause? – Fildor Jun 18 '19 at 11:28
  • You still have to specify the type. Something like: type="System.Web.Security.SqlMembershipProvider" – Shak Ham Jun 18 '19 at 12:58
  • I think the problem is that membership services expects to be using a class named SqlMembershipProvider. It does not know anything about MySqlMembershipProvider. So the problem is to override the Initialize method in the base class. – odbdux Jun 19 '19 at 14:41
  • Fildor, there is an "add name="MySqlMembershipProvider" type= /> directive. – odbdux Jun 19 '19 at 14:45

0 Answers0