How to Configure ASP.NET Membership using SQLMembershipProvider

By | February 5, 2012

In this article, we will learn to configure ASP.NET Membership using SQLMembershipProvider


Objective of this article is to configure ASP.NET Membership to store user information in an external SQL Server database. We will use SQLMembershipProvider for this task.

ASP.NET Membership

ASP.NET Membership enables us to validate and store user information. It creates all the necessary tables and stored procedures to store and manage user credentials. It provides an API that can be used to manage user’s information programmatically.

ASP.NET Membership provides two types of Membership providers:

  1. SQLMembershipProvider: It is used to store user information in a SQL Server database
  2. ActiveDirectoryMembershipProvider: It is used to store user information in an Active Directory.

To configure SQLMembershipProvider first you need to configure your database.

Open Visual Studio Command Prompt (All Programs -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt)

Type command: aspnet_regsql and press Enter

This will launch ASP.NET SQL Server Setup Wizard

Click Next

Leave default selection “Configure SQL Server for application services” and click Next again

Enter server name, Select SQL Server authentication and enter user id and password as in below figure. Select the database you want to configure. Here, I am using Employee database.

Click Next

Click Next and then Finish.

Now, you can see the new tables created in the Employee database for storing user credentials. These table names start with “aspnet_”. Similarly, you can also see new Stored Procedures created in the database with “aspnet_” prefix.

Now, we have configured our Employee database. Our next task is to enable SQLMembershipProvider in a Web application. Follow these steps to do that:

  • Create a new ASP.NET Web Application
  • Add <authentication mode=”Forms”/> in the Web.Config file. ASP.NET Membership works with only Forms Authentication
  • Add following to enable SQLMembershipProvider:
<membership defaultProvider="MyMembershipProvider" >
    connectionStringName="ConString" />
  • Add connection string with name “ConString” to connect with Employee database
    <add name="SqlConString" connectionString="Data Source=localhost\SQL2005EXPRESS; User ID=youruserid; Password=yourpassword; Initial Catalog=Employee;" />

Now, we are ready to use ASP.NET Membership to create new user using CreateUserWizard control and authenticate users using Login control.

0 thoughts on “How to Configure ASP.NET Membership using SQLMembershipProvider

  1. thirureka

    Deepak when i select the server and database after that when i click next I am geetting error like this,

    ” Setup failed.

    An error occurred during the execution of the SQL file ‘InstallCommon.sql’. The SQL error number is 8152 and the SqlException message is: String or binary data would be truncated.

    pls help

  2. thilaga

    Deepak value saved in database but i am not getting mail..pls help me


      We have not set up any mail in this article. We have only configured ASP.NET membership in SQL Server database. Are you referring any other article? Please explain so that I can help you.

  3. yahoo

    No matter if some one searches for his essential thing, so he/she wishes to be available that in detail, thus that thing is maintained over here.

  4. Anees Ahmad

    dear sir, i am new in and i need complete help from creating “CreateUserWizard” to saving data into Database. please share with me overall code.
    thanks for given us such nice bloge


Leave a Reply

Your email address will not be published. Required fields are marked *