MySql ASP.NET Identity 在 Win10 下意外绑定(bind)到 SQL Server

标签 mysql asp.net sql-server asp.net-mvc vb.net

我有一个实时 Web 应用程序(ASP.NET 4.5.1、MVC 5.2.3、EF 6.1、MySql 5.1.35),它在 MS Server2008R2(Web)上运行了几个月没有任何困难。

我正在尝试将我的开发环境移动到 Win10 虚拟机(以前是 Win7 VM),并在 VS2015 中的新机器上打开实时系统和复制数据库的副本。

运行应用程序时(我使用 asp.net Identity 1.0 进行身份验证),我的 _layout.vbhtml 页面出现以下异常:

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)

在:

            <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

因为我没有使用 SQLServer,所以没有处理异常也就不足为奇了...

我很困惑为什么用户对象 (System.Web.Security.RolePrincipal) 使用 SQLClient 而不是指定的 MySQLClient:

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

网络配置:

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

在 Server2008R2 机器上的 VS2015 中运行时,完全相同的项目正确连接到 MySQL 数据库。

在某些情况下,asp.net Identity 是否会“回退”到使用 SQLServer?

最佳答案

做了一些更多的挖掘和谷歌搜索,并在以下位置找到了解决方案:User.IsInRole doesn't work

将以下内容添加到 web.config 解决了问题:

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

RoleManager 默认为 SimpleMembership。我不知道为什么这在一台机器上不是问题,但在另一台机器上却很明显,但显然某处存在歧义,这解决了它。

关于MySql ASP.NET Identity 在 Win10 下意外绑定(bind)到 SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35072568/

相关文章:

php - mysql 查询 wp_post 列表和类别和日期

c# - 使用 Azure 进行身份验证

c# - 有没有办法预览服务器上存储的文档?

SQL Server 2008 - #tmp 表在 exec 命令中运行时引发错误

mysql - 如何链接一个经销商的产品表和多个零售店的关系? mysql

mysql - MySQL单主单从的应用层使用

asp.net - Entity Framework 4 - 从模型更新数据库架构。不删除表数据

sql-server - SQL Server 中不需要的日期时间舍入

python - “ascii”编解码器无法解码 - 通过 pyodbc 将 CSV 转换为 SQL Server

c# - 来自 Docker 的多个 Mysql 连接 -> 套接字错误