Search code examples
asp.netconnection-stringmembership-provider

How to Get the ConnectionString that the Membership Provider is using?


... and not by reading it from the config file! Nor inferring it from anyplace other than be reading exactly what the Membership Provider is itself using. Call me paranoid.

The first data access in my application is an access to the membership provider. The vast majority of connectivity issues have been where the application is deployed to staging or production with a connection string from development, so I'd like to change this:

MembershipUser me = Membership.GetUser();

to this:

MembershipUser me;

try
{
    me = Membership.GetUser();
}

catch ( SqlException E )
{
    Response.Write( "SQL Error " + E.Message + ".<br />" );
    Response.Write( "Connection String: " + Membership.Provider.WHAT? + "<br />" );
}

Seems so obvious, but every reference I find instructs me to use the ConfigurationManager, which is what I specifically don't want to do. Although I concede that such may be my only option, and a satisfactory one at that.

I'm perfectly willing to accept the possibility that my question is on par with this:

int i;

try
{
    i = 42;
}

catch ( Exception e )
{
    Response.Write( "Error assigning literal to integer." );    
}

If this is the case, please comment accordingly.


Solution

  • I don't believe there is a direct property that you can use that will give you the connection information. One thing you could do though is subclass your chosen membership provider and implement your own properties to give you the info.