Arthur Swails Arthur Swails -5 years ago 136
SQL Question

SQL Server error: Why getting error 26 when doing a role system lookup in .NET

I'm getting the error at the bottom when trying to do a Role lookup with a modified version of .NET 's role system.

line of C# code that throws the error 26:

System.Web.Security.Roles.IsUserInRole("blahuser", "blahrole");

This is when I run from localhost. The role system works fine in dev and prod.
Project is set to IIS Express. The other weird thing is this works locally for my boss, but not for any other of the devs here. I am able to connect to the auth database just fine and make edits, in SQL Server Management Studio using my windows creds, or using the connection string user/pass shown below. It is probably a permissions issue, but we dont know which one it might be. My boss has tried all he can think of for now. I forgot to mention I am using the exact same config file as my boss, whos works fine on his local pc.

role manager config is below:

<roleManager enabled="true" cookiePath="/" cookieName="Test" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" cacheRolesInCookie="true" cookieTimeout="30">
<add connectionStringName="DefaultConnection" applicationName="Dovetail.Apps" name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

This connects to our auth database and it should be using this connection string in web.config:

<add name="DefaultConnection" connectionString="Data Source=DtiDevSql201.Dovetail.Local;Initial Catalog=blahauthserver;User ID=blahuser_id;Password=blahpass" providerName="System.Data.SqlClient" />

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)

I have tried all I can from other users who had answers to this question but they didn't work.

Answer Source

Why do you think this is the connection being used? You should have something that looks like this:

  <roleManager defaultProvider="SqlProvider" 

in your configuration and then later something like this:

    applicationName="SampleApplication" />

Please look for those configuration items. Their contents my help you solve the "mystery".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download