carpat
carpat

Reputation: 871

Exception thrown when creating sqlite .net entity data model

I'm trying to get sqlite working with linq. So far I've:

installed the ADO.net providers from http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/

installed both the 32 and 64 bit sqlite .net from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

Now I can create an entity data model using an sqlite database as the source. Whenever I try to create a new instance of the data model (in a wpf component that is getting displayed) I get the following exception:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in     PresentationFramework.dll

Additional information: 'The invocation of the constructor on type myprogram.mycomponent' that matches the specified binding constraints threw an exception.' Line number '13' and line position '37'.

The mycomponent constructor is simply:

private void myprogram()
{
    InitializeComponent();

    pricesEntities pe = new pricesEntities();
}

When I open the design view for the window that displays the component, I get an

ArgumentException was thrown on "mycomponent": Cannot create an instance of "mycomponent".

An Unhandled Exception has occurred

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
  at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
  at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
  at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
  at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
  at myprogram.pricesEntities..ctor() in <path>\prices.Designer.cs:line 34
  at myprogram.ItemList.InitializePriceList() in <path>\ItemList.xaml.cs:line 34
  at myprogram.ItemList..ctor() in <path>\ItemList.xaml.cs:line 29

My app.config contains the following connection string:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="pricesEntities" connectionString="metadata=res://*/prices.csdl|res://*/prices.ssdl|res://*/prices.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;<path>\prices.db&quot;'" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

I tried copying the app.config file to the directory of the executable, as was suggested here and other places. That did not help. Note that this is a different issue than The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid

I have only one project (a wpf application) that I am trying to get to work.

Upvotes: 1

Views: 781

Answers (1)

carpat
carpat

Reputation: 871

Figured out it was because it was an assembly build for the 2.x runtime, so I added the useLegacyV2RuntimeActivationPolicy element to my app.config and that resolved the issue.

Upvotes: 1

Related Questions