Moran Talmon
Moran Talmon

Reputation: 595

How to connect to Membership DB from an ASP.NET application

I am trying to configure my site with ASP.NET Membership to deal with the whole user's login. For some reason, I can't connect to my DB from the ASP configuration screen. All the TCP/IP are enabled in the SQL server configuration, but for some reason my website can't connect.

Upvotes: 1

Views: 1180

Answers (1)

Josh Darnell
Josh Darnell

Reputation: 11433

The relevant things to check for this issue (that come to my mind) are all in the Web.config file for your application.

You should have a connection to the SQL server set up:

<configuration>
    <connectionStrings>
        <add name="ApplicationServices" connectionString="data source=ServerName;Initial Catalog=aspnetdb;User Id=sqlUser;Password=sqlPassword" providerName="System.Data.SqlClient"/>

Note: the "connection string" attribute there should point to your SQLExpress instance.

You should have a membership provider pointing to that connection (with some additional setup parameters:

<membership>
    <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
    </providers>
</membership>

And (possibly) you should have your authentication mode set to forms:

<authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>

Upvotes: 1

Related Questions