开发者

Visual Studio 2010 Add In using Entity Framework

I'm creating an AddIn that launches a Forms-based GUI. The AddIn and the Gui are in different projects. The Gui connects to a database and utilizes EF for the ORM.

When I launch the Gui project from VS, it works great. When I publish that Gui to the vs add-ins folder and run it, it works fi开发者_开发问答ne. When I launch the Gui from the add-in in VS, it loads up fine, but anything that tries to hit the database fails. EF complains about the metadata files.

Exception: The specified named connection is either not found in configuration, not intended to be used with the EntityClient provider, or not valid.

at System.Data.EntityClient.EntityConnection.ChangeConnectionString()

Here is the configuration in app.config

  <connectionStrings>
    <add name="companyEntities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=TESTDB;Initial Catalog=company;Persist Security Info=True;User ID=id;Password=password;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>

The only thing I can think of is that the "res://*/" portion maps differently when the starting assembly is different, but I've tried using absolute paths to the csdl/msl/ssdl files without any success.

What is different about launching the Gui from an Add-In that breaks the configuration?


Don't rely on a connectionString in a config file which you don't control. Instead, pass it explicitly when you new up your context, using the ObjectContext overload which takes a connection string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜