错误“VS2013中的调用目标已抛出异常”

时间:2015-08-09 07:43:13

标签: c# entity-framework visual-studio-2013 sql-server-ce

在我的VS2013项目中参考:

  • EntityFramework 6.1.3,
  • EntityFramework.SqlServerCompact(对于SQLServerCompact 4.0)

我的edx文件中出现错误。 VisualStudio说:

Exception has been thrown by the target of an invocation

并且无法打开或更新edmx文件。

任何人都可以帮忙解决问题吗?

以下是app.config的摘录:

  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="Imir.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <connectionStrings>
    <add name="ImirDBEntities" connectionString="metadata=res://*/ImirDB.csdl|res://*/ImirDB.ssdl|res://*/ImirDB.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;Data Source=C:\ProgramData\Telesto\ImirDB.sdf&quot;"
      providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>

这是我的edmx文件的开头:

<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="ImirDBModel.Store" Alias="Self" Provider="System.Data.SqlServerCe.4.0" ProviderManifestToken="4.0" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
  <EntityContainer Name="ImirDBModelStoreContainer">
    <EntitySet Name="AuthUser" EntityType="ImirDBModel.Store.AuthUser" store:Type="Tables" />
    <EntitySet Name="AuthUserGrant" EntityType="ImirDBModel.Store.AuthUserGrant" store:Type="Tables" />

2 个答案:

答案 0 :(得分:5)

我为私有部署安装了所有nuget软件包,但在打开EDMX图时却出现了相同的错误。

调用目标引发了异常。

Designer未在app.config文件中使用SqlServerCe.4.0提供程序。 尝试暂时删除此行以使其打开:

      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />

答案 1 :(得分:0)

在我的情况下,这是我的连接字符串。非常接近您的连接字符串,可能会将其复制并粘贴到控制台应用程序中,并通过从数据库中获取一行来查看它是否有效。