实体框架:部署时,DBContext无法连接到另一台PC上的服务器

问题描述 投票:0回答:1

我从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>
c# entity-framework exception deployment dbcontext
1个回答
0
投票

如果您使用远程sql server,则必须启用远程系统的防火墙。

请参阅以下链接。 How do I fix the error 'Named Pipes Provider, error 40 - Could not open a connection to' SQL Server'?

© www.soinside.com 2019 - 2024. All rights reserved.