SIGN UP MEMBER LOGIN:    
ARTICLE

Enabling Membership Provider for SQL Server 2005

Posted by Amit Kumar Agrawal Articles | Visual Studio 2010 August 22, 2005
ASP.NET 2.0 brings an important concept called provider model which is used for many new feature i.e. Membership Management, Role Management, Profiles, Web Parts Personalization etc.
Reader Level:

1. Introduction

ASP.NET 2.0 brings an important concept called provider model which is used for many new feature i.e. Membership Management, Role Management, Profiles, Web Parts Personalization etc. By default VS 2005 ships with provider for SQL Express however it provides necessary interfaces for writing custom providers. In this article we will see how to enable provider for SQL Server 2005 without creating a custom provider.

2. Enabling Membership Provider

In this article we will demonstrate the approach to enable the membership provider for SQL Server 2005 however the approach will remain same for other providers i.e. Roles, Profile etc. By default the membership provider (not only membership provider but other providers also) uses SQL Express database. To use your own SQL server database instead of the SQL Express database, you need to create the same database in your SQL Server using aspnet_regsql tool.

After running this utility you can view the aspnetdb database created by opening the SQL server management studio. Please notice various tables created for storing various configuration settings, membership, roles, profile data and personalization data etc.

Now you just need to point the connection string of exiting provider to your database instead of SQL Express database.

Refer the machine.config file stored in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\CONFIG folder.
If you search for membership you will find an entry similar to following

<membership>
<providers
>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" passwordStrengthRegularExpression=""
/>
</providers
>
</
membership>

If you observe the above, you will notice that the membership provider above "AspNetSqlMembershipProvider" uses a connection string LocalServer. If you search for LocalServer in the machine.config file you can see that the same points to the local SQL Express database.

<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"
/>
</connectionStrings>>

Now the easiest thing will be to change the settings of LocalServer and point it to your database instead of SQL Express and that will solve your problem. If you change the settings for the LocalServer connection string, all your providers will point to the SQL Server instead of SQL Express.

Instead of changing the machine.config you can also try following.

Add a connection string in your web.config file, add a provider entry in the web.config file and then point the provider to the connection string as shown below.

<connectionStrings>
<
add name="MySqlProviderConnection" connectionString="server=localhost;integrated security = true;Initial Catalog=aspnetdb"
/>
</
connectionStrings>


<system.web
>
<
membership defaultProvider
="MySqlMembershipProvider">
<
providers
>
<add connectionStringName="MySqlProviderConnection" name="MySqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
/>
</providers
>
</
membership
>
</
system.web>

You can use above approach if you want to use SQL server only for a specific provider and continue using SQL Express for others.

Login to add your contents and source code to this article
share this article :
post comment
 

no... stop using .net. its crap.

Posted by Krivahn Doss Jun 23, 2006

hi buddy,

   it is can work on SQL2000? thx.

  jacky

Posted by jacky Ding Mar 22, 2006
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor