将实体框架与 SQL Compact 私有安装结合使用

发布于 2024-08-27 04:45:16 字数 1508 浏览 4 评论 0原文

我在带有 SQL Compact 的桌面应用程序中使用 Entity Framework 4。我想在我的应用程序中使用 SQL Compact 的私有安装,以便我的安装程序可以安装 SQL Compact,而无需用户进行第二次安装。它还避免了以后的版本控制麻烦。

我的开发计算机已作为公共安装安装了 SQL Compact 3.5 SP1,因此我的应用程序在那里运行良好,正如人们所期望的那样。但它没有在我的测试机器上运行,因为该机器没有安装 SQL Compact。我收到此错误:

The specified store provider cannot be found in the configuration, or is not valid.

我知道有些人在 SQL Compact 私人安装方面遇到困难,但是 我有使用它们一段时间,我真的很喜欢它们。不幸的是,我的常规私人安装方法不起作用。我检查了我的SQL CE文件上的版本号,它们都是3.8.8078.0,这是SP2 RC版本。

以下是我在私人安装中包含的文件:

  • sqlcecompact35.dll
  • sqlceer35EN.dll
  • sqlceme35.dll
  • sqlceqp35.dll
  • sqlcese35.dll
  • System.Data.SqlServerCe.dll
  • System.Data.SqlServerCe.Entity.dll

我添加了对 System 的引用.Data.SqlServerCe 添加到我的项目中,并且我已验证上面列出的所有文件都已复制到安装计算机上的应用程序文件夹中。

以下是我在打开 SQL Compact 文件时用于配置 EntityConnectionStringBuilder 的代码:

var sqlCompactConnectionString = string.Format("Data Source={0}", filePath);

// Set Builder properties
builder.Metadata = string.Format("res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl", edmName);
builder.Provider = "System.Data.SqlServerCe.3.5";
builder.ProviderConnectionString = sqlCompactConnectionString;
var edmConnectionString = builder.ToString();

我是否缺少文件?我是否缺少告诉实体框架在哪里可以找到我的 SQL Compact DLL 所需的配置步骤?对于 EF 在安装计算机上找不到我的 SQL Compact DLL 的任何其他建议吗?感谢您的帮助。

I am using Entity Framework 4 in a desktop application with SQL Compact. I want to use a private installation of SQL Compact with my application, so that my installer can install SQL Compact without giving the user a second installation to do. It also avoids versioning hassles down the road.

My development machine has SQL Compact 3.5 SP1 installed as a public installation, so my app runs fine there, as one would expect. But it's not running on my test machine, which does not have SQL Compact installed. I get this error:

The specified store provider cannot be found in the configuration, or is not valid.

I know some people have had difficulty with SQL Compact private installations, but I have used them for a while, and I really like them. Unfortunately, my regular private installation approach isn't working. I have checked the version numbers on my SQL CE files, and they are all 3.8.8078.0, which is the SP2 RC version.

Here are the files I have included in my private installation:

  • sqlcecompact35.dll
  • sqlceer35EN.dll
  • sqlceme35.dll
  • sqlceqp35.dll
  • sqlcese35.dll
  • System.Data.SqlServerCe.dll
  • System.Data.SqlServerCe.Entity.dll

I have added a reference to System.Data.SqlServerCe to my project, and I have verified that all of the files listed above are being copied to the application folder on the installation machine.

Here is the code I use to configure an EntityConnectionStringBuilder when I open a SQL Compact file:

var sqlCompactConnectionString = string.Format("Data Source={0}", filePath);

// Set Builder properties
builder.Metadata = string.Format("res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl", edmName);
builder.Provider = "System.Data.SqlServerCe.3.5";
builder.ProviderConnectionString = sqlCompactConnectionString;
var edmConnectionString = builder.ToString();

Am I missing a file? Am I missing a configuration stepp needed to tell Entity Framework where to find my SQL Compact DLLs? Any other suggestions why EF isn't finding my SQL Compact DLLs on the installation machine? Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

桃扇骨 2024-09-03 04:45:16

我想出了如何做到这一点,感谢 Steve Lasker 的博客文章。基本上,您需要执行以下操作:

(1) 在项目中设置对 System.Data.SqlServerCe.dll 的引用。将 CopyLocal 属性设置为 True。

(2) 在项目的 App.config 中,添加以下 XML 标记。它告诉 EntityFramework 查找您的 SQL Compact 的私有安装作为其数据提供程序:

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

(3) 在安装项目中,将以下文件添加到文件系统编辑器中的应用程序文件夹中:

  • sqlcecompact35.dll
  • sqlceme35.dll
  • sqlcese35.dll
  • System.dll数据.SqlServerCe.Entity.dll

I figured out how to do it, thanks to a blog post by Steve Lasker. Basically, here is what you have to do:

(1) Set a reference to System.Data.SqlServerCe.dll in your project. Set the CopyLocal property to True.

(2) In the App.config for your project, add the following XML markup. It tells EntityFramework to look to your private installation of SQL Compact for its data provider:

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

(3) In the Setup project, add the following files to the Application Folder in the File System Editor:

  • sqlcecompact35.dll
  • sqlceme35.dll
  • sqlcese35.dll
  • System.Data.SqlServerCe.Entity.dll
仅此而已 2024-09-03 04:45:16

仅供记录,对于 SQL CE 4,web.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.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>

私有部署时的 Version=4.0.0.1 和私有部署时的 Version=4.0.0.0一般部署的情况。

Just for the record, with SQL CE 4 the web.config entries are the following:

  <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.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>

Version=4.0.0.1 in case of a private deployement and Version=4.0.0.0 in case of a general deployment.

御弟哥哥 2024-09-03 04:45:16

谢谢你的提示 - 对我帮助很大。
有一个 SQL Server Compact-Team 博客上的帖子 其中添加了有关 Sql Server Compact 3.5 SP2 版本的一些附加信息。

在与 sql server Compact 的私有部署斗争了一段时间后,我发现了一些额外的要求。

我在几个不同的系统上尝试了我的应用程序,发现我的应用程序在其中一些系统上无法正常工作。

示例:试试这个:

-我已经设置了一个干净的 winxp sp3 安装

-安装了 .net Framework 4.0 扩展

-将我的应用程序部署到新安装(包括您/sql server 紧凑团队博客文章中描述的所有必要的 dll 和调整)

因此,经过一些研究,我发现除了安装 .net Framework 4 之外,我还必须安装 .net Framework 2 并且它工作得很好。

所以这是我的问题:sql server精简版使用了哪个组件不包含在.net框架4中?

我不想超载我的设置并将两个框架链接到我的引导程序......
有谁知道有什么好的Tip吗?

非常感谢 sql server Compact 团队!

SQL Server Compact v3.5 依赖于“Visual C++ Runtime 2005(或8.0)”(也称为 CRT80)。我们将 CRT80 模块封装在 MSI 中。如果是私有部署,
你需要处理这种依赖性。系统上的 .NET FX v2.0 会自动工作,因为 .NET FX v2.0 还打包并安装 CRT80 模块。

thanks for your tip - helped me alot.
There's a post on the SQL Server Compact-Team blog which add some additional information for the Sql Server Compact 3.5 SP2 release.

After struggling for a while with the private deployment of sql server compact i found out some additional requirements.

I tried out my app on several different systems and recognized that my app not worked properly on some of them.

Example: Try this:

-I've set up a clean winxp sp3 installation

-installed the .net Framework 4.0 extended

-deployed my app to the new installation (including all necessary dll's and tweaks described in your/sql server compact team blog post's)

So, after some research i found out that in addition to the .net framework 4 installation i had to install the .net framework 2 as well and it worked fine.

So here is my question: which component is used by the sql server compact edition which is not contained in the .net framework 4?

I don't want overload my setup and chain two frameworks to my bootstrapper...
Does anybody know any good Tip?

Many thanks to the sql server compact Team!

SQL Server Compact v3.5 depends on ‘Visual C++ Runtime 2005 (or 8.0)’ (also known as CRT80). We package the CRT80 modules in our MSI. In case of private deployment,
you need to take care of this dependency. Things work with .NET FX v2.0 on the system automatically because .NET FX v2.0 also packages and installs CRT80 modules.

标点 2024-09-03 04:45:16

这对我有用:

你有一个 dotNet 版本 2.0 和 4.0 的 machine.config 文件:

dotNET 2.0

C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

dotNet 4.0

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

如果您打开 2.0 版本的文件,您将看到它有一个。节点,它可能看起来像这样:

<system.data>
    <DbProviderFactories>
        <add name="Odbc Data Provider" ... stuff here ... />
        <add name="OracleClient Data Provider" ... stuff here ...>
        ... more lines similar to the one above ...
        <add name="Microsoft SQL Server Compact Data Provider" Invariant="System.Data.SqlServerCe.3.5" ...>
    </DbProviderFactories>
</system.data>

然而,如果你打开 dotNet 4.0 的节点,它看起来更悲惨地像:

<system.data>
    <DbProviderFactories>        
    </DbProviderFactories>
</system.data>

或者它甚至没有。根本没有节点!!!无论哪种情况,只需将复制到即可。整个节点从 v2 的 machine.config 文件到 v4 的 machine.config 文件。

旁注

如果您在保存对 v4 machine.config 的编辑时遇到问题,那么您可能需要在单击编辑器启动图标时右键单击几次,才能在管理模式下运行。

This is what worked for me:

You've got a machine.config file for dotNet versions 2.0 and 4.0:

dotNET 2.0

C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

dotNet 4.0

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

If you open up the file for version 2.0, you'll see that it has a <system.data> node, which probably looks something like this:

<system.data>
    <DbProviderFactories>
        <add name="Odbc Data Provider" ... stuff here ... />
        <add name="OracleClient Data Provider" ... stuff here ...>
        ... more lines similar to the one above ...
        <add name="Microsoft SQL Server Compact Data Provider" Invariant="System.Data.SqlServerCe.3.5" ...>
    </DbProviderFactories>
</system.data>

Whereas, if you open up the one for dotNet 4.0, it looks rather more miserably like:

<system.data>
    <DbProviderFactories>        
    </DbProviderFactories>
</system.data>

Or maybe it doesn't even have a <system.data> node at all !!! In either case, simply copy the <system.data> node in it's entirety from the machine.config file for v2 to the one for v4.

SIDE NOTE

If you are having trouble saving your edit of the v4 machine.config, then you might have to right click a couple of times when clicking on the editor launch icon so as to get to the run in admin mode.

晌融 2024-09-03 04:45:16

遇到同样的问题,

“在配置中找不到指定的商店提供程序或无效。”

我来到了这个帖子。
我几乎尝试了一切。
我已经使用 nuget 安装了“System.Data.SqlServerCe”。

所以我已经在我的 web.config 中添加了以下代码行但

<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" />
  <!--<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />-->
  <!--<add name="Microsoft EntityClient" invariant="System.Data.EntityClient.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.EntityClient, System.Data.EntityClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />-->
</DbProviderFactories>

错误仍然存​​在..

我通过取消注释上面代码中的最后两行注释来解决问题...所以现在它变成了

<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" />
  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  <add name="Microsoft EntityClient" invariant="System.Data.EntityClient.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.EntityClient, System.Data.EntityClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>

希望它有帮助..
谢谢。

Being stuck with the same problem,

"the specified store provider cannot be found in the configuration or is not valid."

I came around this post.
I tried almost everything.
I had installed "System.Data.SqlServerCe" using nugets.

So i already had below line of code added in my web.config

<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" />
  <!--<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />-->
  <!--<add name="Microsoft EntityClient" invariant="System.Data.EntityClient.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.EntityClient, System.Data.EntityClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />-->
</DbProviderFactories>

Still the error continued..

I got rid of problem by uncommenting the last two commented lines in above code...so now it becomes

<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" />
  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  <add name="Microsoft EntityClient" invariant="System.Data.EntityClient.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.EntityClient, System.Data.EntityClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>

Hope it helps..
Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文