0

This is a WPF app which references an Entity Framework class library. In the App.config of the class library project I have this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

All very standard. What I want to do is to add a connection string which will enable me to connect to remote server via a URL to the database. Is this going to be possible?

I've tried something like this:

<connectionStrings>
    <add name="LanguageEntities" connectionString="metadata=res://*/LanguageModel.csdl|res://*/LanguageModel.ssdl|res://*/LanguageModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=http://www.myweb.net:667;User ID=Remote;Password=cleverstring;initial catalog=LanguageModel.LanguageEntities;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

But my app seems to default to the local connection without giving me an error message.

Any suggestions gratefully received.

Many thanks!

Shunyata Kharg
  • 927
  • 3
  • 14
  • 26
  • Can you be more specific. What is the error message? How are you trying to open the connection in code? Why aren't you just changing the default connection string? – Tjaart Jun 29 '12 at 14:54
  • Thanks Tjaart. There is no default connectionString I can find, certainly not in the App.config file. The connectionString I specify I add to the App.config file. As I say, there is no error, the app simply connects to the local DB instead of the remote one. Sorry I can't be more specific. – Shunyata Kharg Jun 29 '12 at 18:36
  • Are you using CodeFirst or you are using ObjectContext? If you are using ObjectContext that the config with section name = 'entityframework' is not relevant (and also something is wrong there since there is no Version=4.4.0.0 of EF). If you are using ObjectContext - show the ctor of the class derived from ObjectContext and how you create your context. In general you need to pass the name of the connection string you want to use - I believe that it should look like this in your case public MyContext() : base("name=LanguageEntities") { } – Pawel Jun 29 '12 at 20:55
  • Thanks Pawel. No, using Entity Framework v5.0 RC (I think it was) code first (not objectcontext). – Shunyata Kharg Jul 01 '12 at 21:01
  • Are you passing the connection string in when you create your context? – Tjaart Jul 02 '12 at 09:24

0 Answers0