I found this problem as I was extending a SharePoint site to use FBA and the client wanted the users of Site 2 in a different database than that of Site 1.
Here are some concepts first
You have multiple FBA profile providers , Membership Provider , and Role Provider.
You need to have the following per site
Site1
- Site1MembershipProvider
- Site1RoleProvider
- Site1ProfileProvider
Site2
- Site1MembershipProvider
- Site1RoleProvider
- Site1ProfileProvider
Etc,…
All in one web.Config file / application
While that is obviously not doable without custom provider , yet , you will still have the challenge of dynamically switching the provider at runtime.
Here is the fix no coding needed.
ProfileCommon class only points to the properties under the Default provider
Yet, you can trick it with the following.
<profile enabled=”true” defaultProvider=”SQLProfile”>
<!– The “name” attribute of each property entry corresponds, that is the ProfileCommon properties–>
<properties>
<add name=”FirstName” />
<add name=”MiddleName” />
<add name=”LastName” />
<!– Required Sharepoint properties follow… –>
<add name=”PreferredName” defaultValue=”NA” />
<add name=”WorkEmail” defaultValue=”unknown@NA.com” />
<add name=”WorkPhone” type=”System.String” defaultValue=”NA” />
<!– Required for the Custom Profile Site1 –>
<add name=”Site1FirstName” type=”string” provider =”FBASite1Profile”/>
<add name=”Site1MiddleName” type=”string” provider =”FBASite1Profile”/>
<add name=”Site1LastName” type=”string” provider =”FBASite1Profile”/>
</properties>
<providers>
<add name=”SQLProfile” type=”System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” connectionStringName=”AspNetSqlProvider” applicationName=”/” />
<add name=”FBASite1Profile” type=”System.Web.Profile.SqlProfileProvider” connectionStringName=”FBASite1ConnectionString” applicationName=”Site1Application” />
</providers>
<add name=”FBASite2Profile” type=”System.Web.Profile.SqlProfileProvider” connectionStringName=”FBASite2ConnectionString” applicationName=”Site2Application” />
</providers>
<add name=”FBASite3Profile” type=”System.Web.Profile.SqlProfileProvider” connectionStringName=”FBASite3ConnectionString” applicationName=”Site3Application” />
</providers>
</profile>
Accessing the profile through code
Creating a profile
MembershipUser newUser = Membership.Providers[“Site1Membership”].CreateUser(UsernameTextbox.Text, PasswordTextbox.Text,EmailTextbox.Text, passwordQuestion,passwordAnswer, chkActive.Checked,(object)Guid.NewGuid(), out status);
ProfileCommon pc = (ProfileCommon)ProfileBase.Create(newUser.UserName);
pc.SetPropertyValue(“Site1FirstName”, FirstName.Text);
pc.SetPropertyValue(“Site1MiddleName”, MiddleName.Text);
pc.SetPropertyValue(“Site1LastName”, LastName.Text);
pc.Save();
Reading a profile
MembershipUser user = Membership.Providers[“Site1Membership”].GetUser(username,false);
ProfileCommon pc = (ProfileCommon)ProfileBase.Create(user.UserName);
FirstName.Text = pc.GetPropertyValue(“Site1FirstName”).ToString() ;
MiddleName.Text= pc.GetPropertyValue(“Site1MiddleName”).ToString();
LastName.Text = pc.GetPropertyValue(“Site1LastName”).ToString();
Good Luck .