Page view counter

Unable to use connectionStringName in a Custom Membership Provider definition

Last post 03-08-2007 10:56 AM by James_2JS. 23 replies.

Sort Posts:

  • Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 10:23 AM
    • Loading...
    • KarlR
    • Joined on 02-02-2007, 3:07 PM
    • Sarasota, FL, USA
    • Posts 175
    • Points 77

    I have created a custom membership provider that is declared in the web.config file like this:

    <add name="MyMembershipProvider"

          type="MyMembershipProvider"

          requiresQuestionAndAnswer="True"

          enablePasswordRetrieval="True"

          enablePasswordReset="True" 

          connectionString="Data Source=Karlweb;Initial Catalog=Reports;Persist Security Info=True;User ID=VBUser;Password=Password"

          providername="System.Data.SqlClient"/> 

    This works, but I am technically defining my db connection in two places: the ConnectionString property for the whole site (named "ReportsConnectionString" AND this one for the Membership provider.  I want to just call it out in the site connectionstring and reference that in the one for the provider.  I tried this:

    <add name="MyMembershipProvider"

          type="MyMembershipProvider"

          requiresQuestionAndAnswer="True"

          enablePasswordRetrieval="True"

          enablePasswordReset="True"

          connectionStringName="ReportsConnectionString"

          providername="System.Data.SqlClient"/>

    ..but I keep getting a "connectionstring property has not been initialized" error when I attempt to use the custom Membership Provider.  I thought I should be able to just reference an existing connectionstring by using the "connectionStringName" property (?).  Can anyone see where I am going wrong?

     I would greatly appreciate any suggestions.  Thank you!

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 11:37 AM
    • Loading...
    • James_2JS
    • Joined on 02-13-2006, 10:21 AM
    • Posts 335
    • Points 1,526

    I know this is for a RoleProvider and not a MembershipProvider, but the principal is the same... this works for me...

    <

    roleManager enabled="true" defaultProvider="OracleRoleProvider">

    <

    providers>

    <

    clear/>

    <

    add connectionStringName="SpecRefConnection" name="OracleRoleProvider" type="OracleRoleProvider" applicationName="SPEC_REF"/>

    </

    providers>

    </

    roleManager>

    Perhaps it's the ProviderName causing an issue??

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 1:20 PM
    • Loading...
    • KarlR
    • Joined on 02-02-2007, 3:07 PM
    • Sarasota, FL, USA
    • Posts 175
    • Points 77

    James, thanks for your reply.  I probably should have posted my entire MembershipProvider tag:

    <membership defaultProvider="MyMembershipProvider">

      <providers>

    <add name="MyMembershipProvider"

          type="MyMembershipProvider"

          requiresQuestionAndAnswer="True"

          enablePasswordRetrieval="True"

          enablePasswordReset="True" 

          connectionString="Data Source=Karlweb;Initial Catalog=Reports;Persist Security Info=True;User ID=VBUser;Password=Password"

          providername="System.Data.SqlClient"/> 

      </providers> 

    I think I got the ProviderName correct, but I am still experiencing this error.  Is there another related setting that I need to change in order to use this property?

    Thanks again!

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 1:28 PM
    • Loading...
    • justenough
    • Joined on 03-10-2004, 4:15 PM
    • Posts 54
    • Points 135
    Can you post the <connectionStrings> section in your config file?

     
  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 1:30 PM
    • Loading...
    • James_2JS
    • Joined on 02-13-2006, 10:21 AM
    • Posts 335
    • Points 1,526

    Sorry... I wasn't clear there... I don't think you need the providername, as it will pick this up from the connectionstring...

    So let's see what your connection strings section looks like!!

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 1:44 PM
    • Loading...
    • KarlR
    • Joined on 02-02-2007, 3:07 PM
    • Sarasota, FL, USA
    • Posts 175
    • Points 77

    You were right - I should have also posted my ConnectionString setting (whups).  Here it is: 

    <connectionStrings>

      <add name="Project_Management.My.MySettings.WebReportsConnectionString"

          connectionString="Data Source=Karlweb;Initial Catalog=Reports;Persist Security Info=True;User ID=VBUser;Password=Password"

          providerName="System.Data.SqlClient" />

    </connectionStrings>

    And for the record, I have tried both "WebReportsConnectionString" and "Project_Management.My.Settings.WebReportsConnectionString" & got the same error.  As you can see, the connectionstring is identical, so it would be ideal to work this out so I don't have to change it in two places.

    Again, thank you for your quick replies!

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 2:07 PM
    • Loading...
    • justenough
    • Joined on 03-10-2004, 4:15 PM
    • Posts 54
    • Points 135

    To me it seems the problem is the peirods in the name.  When you tried it with only WebReportsConnectionString, are you sure you had the spelling and everything correct? 

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 2:18 PM
    • Loading...
    • KarlR
    • Joined on 02-02-2007, 3:07 PM
    • Sarasota, FL, USA
    • Posts 175
    • Points 77

    Yup - I copy & pasted it just to make sure.  Even the capitalization is the same.

    Sorry - I don't know what I am doing wrong.  Thanks again.

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 3:22 PM
    • Loading...
    • justenough
    • Joined on 03-10-2004, 4:15 PM
    • Posts 54
    • Points 135
    can you tell me the exact error message that you're getting
  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 3:56 PM
    • Loading...
    • KarlR
    • Joined on 02-02-2007, 3:07 PM
    • Sarasota, FL, USA
    • Posts 175
    • Points 77

    It's still the same as my original post: "connectionstring property has not been initialized".  This only happens when I trigger something that uses the membership provider (like logging in, for example).

    Thanks again.

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 4:11 PM
    • Loading...
    • justenough
    • Joined on 03-10-2004, 4:15 PM
    • Posts 54
    • Points 135
    Try removing the following line from the Membership Provider section; 

    providerName

    ="System.Data.SqlClient"
  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 4:32 PM
    • Loading...
    • KarlR
    • Joined on 02-02-2007, 3:07 PM
    • Sarasota, FL, USA
    • Posts 175
    • Points 77

    Unfortunately, I still get the same error.  I tried a couple of different versions of the connectionStringName value as well, without success.

    I appreciate your continued suggestions.  I will keep experimenting, but please let me know if you think of anything else.

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 4:41 PM
    • Loading...
    • justenough
    • Joined on 03-10-2004, 4:15 PM
    • Posts 54
    • Points 135
    I assume that because this is a custom provider, you have a class called MyMembershipProvider.  Can you show me the code in that class that reads the connection string out of the config file?
  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-07-2007, 7:10 PM
    • Loading...
    • James_2JS
    • Joined on 02-13-2006, 10:21 AM
    • Posts 335
    • Points 1,526

    I would change this to be name="WebReportsConnectionString" - forget about everything else... and then use WebReportsConnectionString in you MembershipProvider definition... and ditch the ProviderName entry there too!!

  • Re: Unable to use connectionStringName in a Custom Membership Provider definition

    03-08-2007, 7:15 AM
    • Loading...
    • KarlR
    • Joined on 02-02-2007, 3:07 PM
    • Sarasota, FL, USA
    • Posts 175
    • Points 77

    You are right - I do have a class called MyMembershipProvider.  When I use my original web config settings (where I call out the the duplicate connection string setting), it works great.  I am just trying to have the MembershipProvider use a reference to my <connectionstrings> section.  Here is what the MyMembershipProvider.vb file looks like:

    Imports Microsoft.VisualBasic

    Imports System.Data

    Imports System.Data.SqlClient

    Imports Project_Management.Functions 'This was required to access the e-mail function in this class (?)

     

    Public Class MyMembershipProvider

        Inherits MembershipProvider

     

        '---for database access use---

        Private connStr As String 'Connection string (populated on Initialize)

     

        Private _requiresQuestionAndAnswer As Boolean

        Private _minRequiredPasswordLength As Integer

     

        Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Specialized.NameValueCollection)

     

            '===retrives the attribute values set in

            'web.config and assign to local variables===

     

            If config("requiresQuestionAndAnswer").ToUpper = "TRUE" Then _

                _requiresQuestionAndAnswer = True

     

            connStr = config("connectionString")

            MyBase.Initialize(name, config)

        End Sub

    James, I did try what you suggested, but I still got the same error.  Could you use the examples in my earlier post to show me exactly what you mean?  Thank you!

Page 1 of 2 (24 items) 1 2 Next >