我从DbContext创建了一个模型,并在app配置文件中存储了连接字符串。它在我的电脑上完美运行。但是,当我将它部署到另一台PC时,它会引发异常
建立与SQL Server的连接时发生与网络相关或特定于实例的错误。
服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。
(提供者:命名管道提供程序,错误:40 - 无法打开与SQL Server的连接)
public class FoodIndustryContext:DbContext
{
public FoodIndustryContext (): base("name = FoodIndustryContextDB") { }
public DbSet<Industry> Industries { get; set; }
public DbSet<Purchase> Purchases { get; set; }
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name = "FoodIndustryContextDB"
connectionString = "Data Source =.;Initial Catalog = FoodIndustryDemo;Integrated Security = true"
providerName = "System.Data.SqlClient"/>
</connectionStrings>
</configuration>
如果您使用远程sql server,则必须启用远程系统的防火墙。