简体   繁体   中英

Connecting to a SQL Server using Entity Framework 4

So on my development machine I have SQL Server Express and Visual Studio installed. I finished creating the application and everythings working. Here is the connection string in the App.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="ColegioDBEntities"
         connectionString="metadata=res://*/Repositories.ColegioModel.csdl|res://*/Repositories.ColegioModel.ssdl|res://*/Repositories.ColegioModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;Initial Catalog=ColegioDB;Integrated Security=True;MultipleActiveResultSets=True&quot;"
         providerName="System.Data.EntityClient" />
  </connectionStrings>

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
</configuration>

I created an installation project and want to install the application on a Virtual Machine (to simulate deployment conditions) which is on the same network as where the SQL Server Express is installed. What would the connection string be? Like, 192.168.2.102/SQLExpress?

Any ideas?

surely the IP address or host name will be needed then the instance name of SQL Express. Consider that by default SQL Express is installed with tcp and named pipes disabled so you have to enable those facilities in the configuration manager before you could access it remotely from another machine.

The sql connection string is part of the "connectionString" attribute and is encoded as a substring with masked quotes:

provider connection string=&quot;Data Source=.\SQLEXPRESS;Initial Catalog=ColegioDB;Integrated Security=True;MultipleActiveResultSets=True&quot;

so the config for your ip adress must look like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="ColegioDBEntities"
         connectionString="metadata=res://*/Repositories.ColegioModel.csdl|res://*/Repositories.ColegioModel.ssdl|res://*/Repositories.ColegioModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=192.168.2.102\SQLEXPRESS;Initial Catalog=ColegioDB;Integrated Security=True;MultipleActiveResultSets=True&quot;"
         providerName="System.Data.EntityClient" />
  </connectionStrings>

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
</configuration>

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