ASP.NET authentication using SQL 2005
April 30th, 2007 — ¥ong¥s
Online project management, task software, and free collaboration workspace: AJAXWorkspace
AJAXWorkspace is a free online workspace that offers task tracking software, team collaboration, online calendar, document sharing, and file management for project management and teamwork. |
There are conditions where we have our development environment on a SQL express (vs 2005) machine and we are trying to get the same code to run on a SQL Server 2005 machine. But, we cannot connect to the ASP.NET provider db even after registering a sql db in asp_net_regsql or something like that. By default, it uses whatever settings are in the machine.config file. So, that file usually has the settings that point to using a LocalSqlServer connection string, which is also defined in the machine.config as a user instance DB in the DataDirectory.
There are 2 ways to make it works:
- Removing the LocalSqlServer connection string and then adding one to your point to your DB in web.config. The connection strings section of your web.config file should look something like this:
<connectionStrings>
<remove name=”LocalSqlServer”/>
<add name=”LocalSqlServer”
connectionString=”Data Source=Server\Instance; Integrated Security=SSPI; Initial Catalog=database;”
providerName=”System.Data.SqlClient”/>
</connectionStrings> - Provide your own <membership> section and specify the specific connection & provider type to use for membership.
<configuration>
<connectionStrings>
<add name=”MySqlConnection” connectionString=”Data
Source=MySqlServer;Initial Catalog=aspnetdb;Integrated
Security=SSPI;” />
</connectionStrings>
<system.web>
<membership defaultProvider=”SqlProvider” userIsOnlineTimeWindow=”15″>
<providers>
<clear />
<add
name=”SqlProvider”
type=”System.Web.Security.SqlMembershipProvider”
connectionStringName=”MySqlConnection”
applicationName=”MyApplication”
enablePasswordRetrieval=”false”
enablePasswordReset=”true”
requiresQuestionAndAnswer=”true”
requiresUniqueEmail=”true”
passwordFormat=”Hashed” />
</providers>
</membership>
</system.web>
</configuration>
* Thanks to Shawn Cicoria and George McKee for the solution.