简体   繁体   中英

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.

I get this error : System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: 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.

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.

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"

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.

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.

Additionally, you specify an Initial Catalog in your connection string, which I assume is pointing at your new DB. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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