Sitemap Security Trimming throws SQL error
Asked Answered
C

5

6

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

Chickpea answered 7/2, 2012 at 8:27 Comment(5)
Hello, can you please put out the exact exception you are getting + any stack trace.Rebba
And you're absolutely sure that the DB connection is, in fact, correct?Icao
Is your asp:sitemapdatasource then like <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" SiteMapProvider="XmlSiteMapProvider" />Eliseelisee
Yes, the connection is correct. Im sure because if I take out the trimming, the membership and roles work 100%Chickpea
Yes its: <asp:SiteMapDataSource runat="server" ID="MainSiteMapDataSource" ShowStartingNode="False" SiteMapProvider="XmlSiteMapProvider"/>Chickpea
P
2

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.

Porterporterage answered 21/2, 2012 at 14:54 Comment(0)
W
0

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>
Wallflower answered 17/2, 2012 at 3:11 Comment(0)
W
0

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.

Wallflower answered 21/2, 2012 at 16:47 Comment(0)
Y
0

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...

Yen answered 21/2, 2012 at 17:6 Comment(0)
M
0

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”

Mafalda answered 21/2, 2012 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.