title: Using ASP.Net SqlMembershipProvider with multiple databases
body: <p>I'm in a situation where I need to have my SQLMembershipProvider looking at two different databases. I'm able to set the connection string of the provider programmatically in the first instance, but am unable to change it for subsequent uses.</p>
  
  <p>Does anyone know if this is possible and if so, how?</p>
  
  <p>Thanks!</p>
  
  <pre><code>public class CustomSqlMembershipProvider : SqlMembershipProvider
  {
      public static string connectionString { get; set; }
  
      public override void Initialize(string name, NameValueCollection config)
      {
          DatabaseConfig _config = DatabaseConfig.GetInstance();
  
          if (String.IsNullOrEmpty(connectionString)) 
              connectionString = _config.BuildConnectionString(DatabaseConfig.enumConnectionString.MyRedsourceDev);
          config["connectionString"] = connectionString;
          base.Initialize(name, config);
  
          //Also tried this but it doesn't work
          // Set private property of Membership provider.
          //FieldInfo connectionStringField = GetType().BaseType.GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
          //connectionStringField.SetValue(this, connectionString);
      }
  }
  </code></pre>
  
  <p>I can't help but think that the problem is because the Initialize method is only called once- when the user logs in. As far as I can see, the connection string is unable to change after this point, even if I set the connectionString property.</p>
  
  <p>I have noticed that there is a private field called '_Initialzed' which I've tried to set to false using the same Reflection code above in the hope of forcing the provider to re-initialise each time, but to no avail</p>