MVC4网站只能在一台PC上运行,而不是在其他PC上,“SQL网络接口失败,错误:26”

时间:2013-01-22 22:25:10

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

以下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 - 查找指定的服务器/实例时出错)

工作机器具有此DB连接: enter image description here

使用localDBsqlexpress作为连接并不重要;让这个成功很重要。

DbContext上课:

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

不知怎的,这解决了这一切。

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

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