Click here to Skip to main content
15,889,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm trying to use membership in my ASP.Net project in VS2010.

first: I create database with aspnet_regsql (with a custom name);

second: in my web.config I wrote:
XML
<configuration>
	<connectionStrings>
		<add name="MySqlConnection" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=Math;Integrated Security=True;User Instance=true;" providerName="System.Data.SqlClient"></add>
	</connectionStrings>
	<system.web>
		<!--<authentication mode="Forms">
			<forms loginUrl="Default.aspx" name=".ASPXFORMSAUTH"/>
		</authentication>-->
		<authorization>
			<deny users="?"/>
		</authorization>
		<membership>
			<providers>
				<add connectionStringName="MySqlConnection" applicationName="MyApplication" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" name="SqlProvider" type="System.Web.Security.SqlMembershipProvider"/>
			</providers>
		</membership>
		<compilation debug="true"/></system.web>
</configuration>



Third: in Administrative tools in Provide section, I got this error:

Could not establish a connection to the database. If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider

where is the problem?
Posted

1 solution

Modify your web.config code as shown below:

<configuration>
    <connectionstrings>
      <add name="MySqlConnection" providername="System.Data.SqlClient">
      connectionString="Server=mssql.world19.server-world.net;Database=micro ;Uid=x123; Pwd=y123" />
    </add></connectionstrings>
    <system.web>
      



      

      <!-- AUTHENTICATION -->
      <authentication mode="Forms">
       <forms loginurl="login.aspx" name=".ASPXFORMSAUTH" />
      </authentication>
      <!-- AUTHORIZATIONN -->
      <authorization>
        <deny users="?" />
      </authorization>
      

     



      <membership defaultprovider="AspNetSqlMembershipProvider" userisonlinetimewindow="15">
        <providers>
          <clear />
          <add name="AspNetSqlMembershipProvider">
              type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
              connectionStringName="MySqlConnection"
              enablePasswordRetrieval="false"
              enablePasswordReset="true"
              requiresQuestionAndAnswer="true"
              applicationName="/"
              requiresUniqueEmail="false"
              passwordFormat="Hashed"
              maxInvalidPasswordAttempts="5"
              minRequiredPasswordLength="7"
              minRequiredNonalphanumericCharacters="1"
              passwordAttemptWindow="10"
              passwordStrengthRegularExpression="" />
        </add></providers>
      </membership>


      <profile>
        <providers>
          <clear />
          <add name="AspNetSqlProfileProvider" connectionstringname="MySqlConnection" applicationname="/">
              type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </add></providers>
      </profile>


      <rolemanager>
        <providers>
          <clear />
          <add name="AspNetSqlRoleProvider" connectionstringname="MySqlConnection" applicationname="/">
              type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
          <add name="AspNetWindowsTokenRoleProvider" applicationname="/">
              type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </add></add></providers>
      </rolemanager>
      

      

      

      

      

      

    </system.web>
  </configuration>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900