0
votes

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?

3
Have you configured membership and a membership provider in your web.config?codemonkeh
That worked. Thanks a lot.ig343
Awesome. I have added the same info as an Answer to help others. If you would be so kind as to accept it.codemonkeh

3 Answers

4
votes

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

1
votes

This is extension of @codkemonkeh answer if you are using SQL Server and not localDB.

My Website Administration tool was running fine until I enabled roles, at which points I started getting this error. So without roles, my application worked fine but with roles enabled, I was getting this error.

Found out that Roles by default use localDB sql connection if default connection is not provided. Since in my case, I was storing user logins in SQL Server (and not in localDB), I was getting this error.

This Microsoft help page exactly shows exactly how to setup default connection for Roles.

<roleManager enabled="true" defaultProvider="SqlRoleManager">
  <providers>
    <add name="SqlRoleManager" 
         type="System.Web.Security.SqlRoleProvider"
         connectionStringName="YOUR_CONNECTION_NAME"
         applicationName="MyApplication" />
  </providers>
</roleManager>

Also note that defaultProvider="SQLRoleManager" and name="SQLRoleManager" ...> should be same.

Other than that @codemonkeh answer (above) is correct. This is just extra problem that I came across.

0
votes

After using [InitializeSimpleMembership] on my HomeController it's solved my Problem.that is "Unable to connect to SQL Server database" when i am checking @if (User.IsInRole("Administrators")).

link: Role based authentication in the new MVC 4 Internet template using simplemembership