简体   繁体   English

无法使用实体框架部署C#应用

[英]cannot deploy c# app with entity framework

i have finished a desktop c# project in which i make use of Entity framework 5 and SQL server 2008 in my machine it's working well, but i created a virtual machine and tried to deploy it there and I have problems. 我已经完成了一个桌面c#项目,其中在我的计算机中使用了Entity Framework 5和SQL Server 2008,它运行良好,但是我创建了一个虚拟机并尝试将其部署在其中,但是我遇到了问题。

I get this error : System.Data.EntityException: The underlying provider failed on Open. 我收到此错误: System.Data.EntityException:基础提供程序在打开时失败。 ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. ---> System.Data.SqlClient.SqlException:建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。

I used installshield for the setup and I have installed sql express in the visrual machine, during the setup I create the database and all the tables. 我使用installshield进行安装,并且在visrual机器中安装了sql express,在安装过程中,我创建了数据库和所有表。

my connection string is this : name="BussinessContainer" connectionString="metadata=.\\Bussiness.csdl|.\\Bussiness.ssdl|.\\Bussiness.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=yingyangDB;User ID=username;Password=password;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" 我的连接字符串是这样的: name="BussinessContainer" connectionString="metadata=.\\Bussiness.csdl|.\\Bussiness.ssdl|.\\Bussiness.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=yingyangDB;User ID=username;Password=password;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" name="BussinessContainer" connectionString="metadata=.\\Bussiness.csdl|.\\Bussiness.ssdl|.\\Bussiness.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=yingyangDB;User ID=username;Password=password;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"

Should I change the connection string? 我应该更改连接字符串吗? I searched a lot before posting this, but nothing worked..any help? 在发布此消息之前,我进行了很多搜索,但没有任何帮助。

SQL Express (normally) doesn't create as a "Default instance" - ie connecting by localhost isn't sufficient to connect to the local SQL express instance. SQL Express(通常)不会创建为“默认实例”-即通过localhost连接不足以连接到本地SQL Express实例。

You may need to use localhost\\SQLExpress to connect to the local SQL Express instance (the instance name may be different, but usually it is not. 您可能需要使用localhost\\SQLExpress连接到本地SQL Express实例(实例名称可能有所不同,但通常不是这样。

Additionally, you specify an Initial Catalog in your connection string, which I assume is pointing at your new DB. 此外,您在连接字符串中指定一个Initial Catalog ,我假设它指向您的新数据库。 However you say that you create the DB during the installation - so that DB may not actually exist in your Instance yet. 但是,您说的是在安装过程中创建了数据库-因此该数据库可能实际上尚未存在于您的实例中。 That may be causing it to fail out. 那可能导致它失败。 Try taking it out of the string and see if that lets you connect. 尝试将其从字符串中取出,看看是否可以连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM