Question

I am using the default Sitemap provider with secutiry trimming. But, some how, I get:

A network-related or instance-specific error occurred while establishing a connection to SQL Server.

I'm thinking the sitemap provider is looking for the roles in the wrong place. My configuration is like this:

<connectionStrings>
   <add name="DB" ... />
</connectionStrings>


   <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
      <providers>
        <clear/>
        <add name="SqlProvider" .../>
      </providers>
    </membership>
    <roleManager enabled="true">
      <providers>
        <add connectionStringName="DB"  type="System.Web.Security.SqlRoleProvider" ... />
      </providers>
    </roleManager>

The Sitemap tag is defined like this:

<siteMap defaultProvider="XmlSiteMapProvider" enabled="true"  >
      <providers>
          <clear/>
          <add name="XmlSiteMapProvider"
            description="Default SiteMap provider."
            type="System.Web.XmlSiteMapProvider "
            siteMapFile="Web.sitemap"
            securityTrimmingEnabled="true"  />
      </providers>
  </siteMap>

Why am I getting the sql error? How does the trimming get the roles?

EDIT: the ysod

Was it helpful?

Solution

The core error from your screenshot is

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

unfortunatly, this is truncated. The message would normally then continue with " is configured to allow remote connections.", and this may further be followed by a specific reason (for example, it may state (amongst various other reasons) "provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified")

However, with the message you have so far, it looks like a connectivity problem between the client machine and the SQL Server box. So I'd look at doing due-diligence against the SQL Server box and network connectivity first:

  • The SQL Server server name can resolve
  • That the server can be reached with ping
  • That SQL server is configured to accept remote connections
  • That the SQL Browser service is running on the SQL Server box
  • That Windows Firewall isn't getting in the way
  • That SQL Server itself is actually running in the first place

If they pass then you need to validate than you can log-on. I'd normally use the SQL management tools, especially the command line tool sqlcmd to test basic connectivity (for example: sqlcmd -E -S mysqlserver\instance to connecto to the default database or sqlcmd -E -S mysqlserver\instance -d database to connect to a specific database). Obviously you'll need to run these as the user that your web application is running as, otherwise they'll attempt to authenticate as you (either use runas or start a command prompt under different credentials [find a command prompt in the start menu then, shift-right-click -> "Run as a different user].

However what would ultimately help would be if you can get the full error message text (rather than the truncated version), then that may help narrow down the specific problem you're having.

OTHER TIPS

Try this working sitemap:

<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
  <providers>
    <add name="XmlSiteMapProvider" description="SiteMap provider which reads in .sitemap XML files." type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true" />
  </providers>
</siteMap>

I would try making a brand new project with just the default role provider and security trimming and see if you can get that working.

If the SqlRoleProvider works without security trimming enabled, my first guess would be that there's something about your database or connection string that is preventing multiple simultaneous connections. This would be quite a bit simpler to evaluate if you could provide the details of your DB connection string...

In general, the configuration looks correct. According to the exception’s message, the database is unavailable. Would you check whether or not a database could be connected?

using (SqlConnection connection = new SqlConnection()) {
    connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
    try {
        connection.Open();
    }
    catch() {
        ...
    }
}

“Steps to troubleshoot SQL connectivity issues”

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top