gpt4 book ai didi

c# - 带有本地 SQL Server CE DLL 的 Entity Framework 代码优先 "ADO.NET provider not found"

转载 作者:太空狗 更新时间:2023-10-29 17:30:06 24 4
gpt4 key购买 nike

我正在编写一个使用 SQL Server CE 4.0 文件的 C# 应用程序,这些文件通过代码优先的方式通过 Entity Framework 6.0 进行访问。 (应用程序需要能够使用本地 dll 进行 SQL Server CE 连接,即应用程序需要 XCOPY 可部署)。该应用程序在我的开发机器上运行良好,但在其他机器上(例如只有 Win7 和 .NET 4.0 的虚拟机),我得到一个 ArgumentException:

The ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.

内部异常消息说:

Unable to find the requested .Net Framework Data Provider. It may not be installed.

我已经搜索了 Google 和 SO,大多数评论都表明确保 App.config 文件是正确的。我相信我的是(默认连接工厂和提供者部分),但这里是内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
</configuration>

构建文件夹包括以下文件(当然,除了应用程序特定的文件):

  • EntityFramework.dll
  • EntityFramework.xml
  • EntityFramework.SqlServer.dll
  • EntityFramework.SqlServer.xml
  • EntityFramework.SqlServerCompact.dll
  • EntityFramework.SqlServerCompact.xml

在每个 amd64 和 x86 子文件夹中都有以下文件:

  • sqlceca40.dll
  • sqlcecompact40.dll
  • sqlceer40EN.dll
  • sqlceme40.dll
  • sqlceqp40.dll
  • sqlcese40.dll

我确定该程序在开发机器上运行,因为已经安装了 SQL Server CE,但是如何让它在其他机器上仅使用本地 SQL Server CE dll 运行?

最佳答案

参见 http://tech.aendeavors.com/2011/06/09/bin-deploy-sqlce-4-0-and-ef-4-1/

看来您可能遗漏的相关部分是:

  • 确保引用了 System.Data.SqlServerCe 并将其设置为“复制本地”在属性中。

  • 将以下内容添加到 app.config:


<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0"
invariant="System.Data.SqlServerCe.4.0"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>

关于c# - 带有本地 SQL Server CE DLL 的 Entity Framework 代码优先 "ADO.NET provider not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20575582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com