iguarna iguarna - 3 months ago 15
SQL Question

ASP.NET WebSite Administration Tool can't access SQL database

I keep getting the following error when I click on the Security tab in ASP.NET WebSite Administration Tool.


A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)


This is exactly what i've done so far:


  1. Create a New Empty Web Site.

  2. Create a Database in
    /App_Data
    named
    ASPNETDB.MDF

  3. Run command line:
    Aspnet_regsql.exe -A all -E -d (mywebsitepath)/App_Data/ASPNETDB.MDF

  4. Go to ASP.NET WebSite Administration Tool and click on the security tab.



What am I doing wrong?

Answer

You need to configure a membership provider in your websites web.config file. Please see the below example and modify the configuration to suit your requirements.

<configuration>
  <connectionStrings>
    <add name="MySqlConnection" connectionString="Data 
      Source=MySqlServer;Initial Catalog=aspnetdb;Integrated
      Security=SSPI;" />
  </connectionStrings>
  <system.web>
    <authentication mode="Forms" >
      <forms loginUrl="login.aspx"
        name=".ASPXFORMSAUTH" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    <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>

For more information please consult the following MSDN articles:

http://msdn.microsoft.com/en-us/library/6e9y4s5t(v=vs.100).aspx

http://msdn.microsoft.com/en-us/library/vstudio/1b9hw62f(v=vs.100).aspx

Comments