1

I have a live web application (ASP.NET 4.5.1, MVC 5.2.3, EF 6.1, MySql 5.1.35) which has worked for months without difficulty hosted on MS Server2008R2(Web).

I am attempting to move my dev environment to a Win10 virtual machine (previously a Win7 VM) and am opening a copy of the live system and replicated DB on the new machine in VS2015.

When running the application (I am using asp.net Identity 1.0 for authentication) I get the following exception in my _layout.vbhtml page:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Web.dll but was not handled in user code

Additional information: 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)

at:

            <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav" style="width:auto;white-space: nowrap;">
                @If (Request.IsAuthenticated) Then
                    @<li>@Html.ActionLink("Home", "Index", New With {.Area = "", .controller = "Home"})</li>

                    If **User.IsInRole("Salesman")** Then

It's not surprising that the exception isn't being handled as I'm not using SQLServer...

I'm baffled why the User object (System.Web.Security.RolePrincipal) is using SQLClient rather than MySQLClient as specified:

Public Class ApplicationDbContext
    Inherits IdentityDbContext(Of ApplicationUser)
    Public Sub New()
        MyBase.New("IMSSecurityEntities")
    End Sub

Web.config:

  <connectionStrings>
    <add name="IMSSecurityEntities" connectionString="data source=localhost;database=db1;Uid=root;Pwd=password;" providerName="mysql.data.mysqlclient" />

The very same project when run in VS2015 on the Server2008R2 machine correctly connects to the MySQL db.

Would asp.net Identity maybe 'fall back' to using SQLServer in certain situations?

Rich Freeman
  • 1,009
  • 2
  • 9
  • 22

1 Answers1

1

Did some more digging and googling and found a solution at: User.IsInRole doesn't work

Adding the following to web.config resolved the issue:

<modules>
    <remove name="RoleManager" />
</modules>

RoleManager was defaulting to SimpleMembership. I don't know why this wasn't a problem on one machine but it was on the other but clearly there was ambiguity somewhere and this sorted it.

Marc.2377
  • 7,807
  • 7
  • 51
  • 95
Rich Freeman
  • 1,009
  • 2
  • 9
  • 22