【问题标题】:MVC4 website only works on one PC, not other PC, fails with "SQL Network Interfaces, error: 26"MVC4 网站只能在一台 PC 上运行,不能在其他 PC 上运行,失败并显示“SQL 网络接口,错误:26”
【发布时间】:2013-01-22 22:25:10
【问题描述】:

以下 MVC4 ef-codefirst 应用程序在我的计算机上运行良好,但在其他任何地方都没有。

VS 2012 Ultimate 和 SQL Express 安装在两台计算机上。

两台电脑都使用这个连接字符串:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-AppointmentMVC4-20130118154339;
Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-AppointmentMVC4-20130118154339.mdf"
providerName="System.Data.SqlClient" />

尝试从开发计算机以外的计算机访问数据库时:

在建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)

工作机器有这个数据库连接:

使用localDBsqlexpress 作为连接无关紧要;让它成功很重要。

DbContext类:

public class AppointmentContext : DbContext
{
    public DbSet<Appointment> Appointments { get; set; }
    public DbSet<User> Users { get; set; }
}

【问题讨论】:

    标签: c# sql-server asp.net-mvc entity-framework ef-code-first


    【解决方案1】:

    我认为 LocalDB 只支持通过命名管道协议进行本地连接。
    http://www.sqlcoffee.com/SQLServer2012_0004.htm

    【讨论】:

      【解决方案2】:

      不知何故,这一切都解决了。

      <add name="AppointmentContext" connectionString="Data Source=
      (LocalDb)\v11.0;AttachDBFilename=|DataDirectory|\Appointments.mdf" 
      providerName="System.Data.SqlClient" />
      

      感谢 Iraklis 和 jessehouwing 的帮助,很棒的社区。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-10
        • 1970-01-01
        • 2021-03-01
        • 1970-01-01
        • 2014-03-02
        • 1970-01-01
        相关资源
        最近更新 更多