下面的 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" />
当尝试从开发计算机以外的计算机访问数据库时:
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)
工作机器有这个数据库连接:
使用localDB
或sqlexpress
作为连接并不重要;让它成功很重要。
DbContext
类:
public class AppointmentContext : DbContext
{
public DbSet<Appointment> Appointments { get; set; }
public DbSet<User> Users { get; set; }
}
最佳答案
我认为 LocalDB 只支持通过命名管道协议(protocol)的本地连接。
http://www.sqlcoffee.com/SQLServer2012_0004.htm
关于c# - MVC4 网站仅适用于一台 PC,不适用于其他 PC,失败并显示 "SQL Network Interfaces, error: 26",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14469186/