views:

106

answers:

1

Hi,

I tried to setup role provider, using this article.

It worked partially - provider created some tables in MySQL, but I cannot access it from ASP.NET Configuration Tool. I get following error, while trying to add some roles (Roles->Create or Manage Roles):

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) at System.Web.Administration.WebAdminPage.CallWebAdminHelperMethod(Boolean isMembership, String methodName, Object[] parameters, Type[] paramTypes) at ASP.security_roles_manageallroles_aspx.BindGrid() at ASP.security_roles_manageallroles_aspx.Page_Load() at System.Web.Util.CalliHelper.ArglessFunctionCaller(IntPtr fp, Object o) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

My Connection string (which works for accesing data with LINQ to MySQL (with dblinq)):

<connectionStrings>
<add name="ZenToolDB" connectionString="Database=zentool;Data Source=localhost;User Id=root;Password=supersecretpassword" providerName="MySql.Data.MySqlClient" />
</connectionStrings>

Any idea, how to make it work? Thanks!

EDIT: Added web.config fragment with providers:

<membership defaultProvider="MySqlMembershipProvider">
      <providers>
        <clear/>
        <add name="MySqlMembershipProvider"
             type="MySql.Web.Security.MySQLMembershipProvider,
             MySql.Web, Version=6.2.2.0, Culture=neutral,
             PublicKeyToken=c5687fc88969c44d"
             autogenerateschema="true"
             connectionStringName="ZenToolDB"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             passwordStrengthRegularExpression=""
             applicationName="/"/>
      </providers>
    </membership>
        <profile>
            <providers>
                <clear />
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ZenToolDB" applicationName="/" />
            </providers>
        </profile>
        <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
      <providers>
        <clear />
        <add connectionStringName="ZenToolDB" applicationName="/" name="AspNetSqlRoleProvider"
            type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <!--
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider"
            type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        -->
      </providers>
    </roleManager>
A: 

There is a role providers section in your web.config, did you make sure that points to the new role provider? If not it is probably trying to use the default SQL Role Provider.

The default looks like this, and uses the System.Web.Security.SqlRoleProvider which appears to be references in your stack trace.

<membership>
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
         enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" />
  </providers>
</membership>

<profile>
  <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
  </providers>
</profile>

<roleManager enabled="false">
  <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
  </providers>
</roleManager>
NickLarsen
Yes, it points to new role provider. Thanks for reply.
kMike
Can you post the entire web.config including role manager, membership and profile sections because the stack trace appears to be using the default role manager. The article you linked only changes the Membership section, not the role management section.
NickLarsen
I added fragment of web.config with sections, you required.
kMike
Oh, I can see now, where may be the problem.
kMike
If you cannot find a MySQL role manager, its pretty easy to implement your own, you just have to use the `System.Web.Security.RoleProvider` (http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx) as a base class and implement the 8 or 10 abstract functions. Takes about an hour or two from knowing nothing about it to being up and running.
NickLarsen
MySQL .NET Connector has its own role provider. I had to change System.Web.Security.SqlRoleProvider to MySql.Web.Security.MySQLRoleProvider. Thanks for your replies.
kMike
Glad you got it all figured out, good luck with your project.
NickLarsen