My approach to this is deleting the aspnetDB database completely and then adding the tables in the aspnetDB to my database. When you do this though, you will need to do some changes in the web.config file to reflect your database as the database to use for membership. Follow the following steps.
1. Backup your project (in case this doesn't go as planned, hahaha!)
2. Delete the aspnetDb database.
3. In this step, you are going to configure your custom database to store information for ASP.Net applications services. So go to Drive C: > Windows > Microsoft.Net > Framework (or Framework64 if on a 64 bit PC like me) > v4.0.xxx (where xxx is th revision number of the version of .Net Framework you have, eg v4.0.30319) > Locate the aspnet_regsql.exe app. > double click
- 3a. In the dialog that opens, read the screen and then click Next
- 3b. On this screen there are two radio buttons. Because you already have a database, choose the first one. Click Next
- 3c. Enter your Server Name ( use '.', dot for local machine), select the credentials for your database server.
- 3d. From the Databases dropdown, select your database. Click Next.
- Read the screen and then click Next
If all goes well, you should see a screen that lets you know. Click Finish.
Now you have completed the first part. The second part is to let asp.net know that you want it to use your database for membership services. To do this, go to web.config. Locate the connectionString for your database. Name the connection string appropriately.
Eg. Change the connectionString below to your liking.
Instead of this,
HTML Code:
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
use
HTML Code:
<connectionStrings>
<add name="MyDbConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|MyCustomDB.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
Now go and locate the machine.config file (usually at C:\Windows\Microsoft.NET\Framework64\v4.0.xxxx\Con fig)
Open the machine.config file VS and locate the following elements under <system.web>:
HTML Code:
<membership>
<providers>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
</providers>
</membership>
<profile>
<providers>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</profile>
<roleManager>
<providers>
<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</roleManager>
Note that the connectionStringName attribute is all set to LocalSqlServer. That is a reference to the aspnetDB database you deleted. Now copy these elements from the machine.config file to your web.config file and replace the value for this attribute to the name you gave the connectionString for your custom database you just modified. You must not make changes to machine.config file. As the name depicts, settings in this file applies to all .net applications you build on this machine. So, make sure to only copy the elements listed above to your application's web.config file before making the changes.
You are all done.
NOTE: If you expand your custom db after running the aspnet_regsql program, you will notice all the necessary tables for keeping records are added.