我认为 sqlite 很简单,但它给我带来了困难。我只想创建一个可以使用 ado.net 实体数据类连接到 sqlite 数据库的应用程序。
我在运行 Windows XP 的虚拟计算机上测试应用程序时遇到此问题。该应用程序在我当前的计算机以及部署它们时在我的笔记本电脑上运行良好。
以下是虚拟计算机上发生的情况:
- 该应用程序能够启动。
- 应用程序能够使用 System.Data.SQLite 与数据库交互
- 应用程序无法使用 ADO.NET 实体数据模型连接到数据库
当我尝试连接时出现以下异常:
我知道有很多帖子讨论这个问题,其中大多数都说您需要下载Sqlite 的 .NET 提供程序。 http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
我已经安装了 sqlite-netFx40-setup-bundle-x86-2010-1.0.79.0.exe 并且遇到了同样的问题。我应该怎么办?
Edit
我设法通过添加以下内容建立连接:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
到我的 app.config 文件。
问题是现在我无法选择数据也无法将记录插入数据库。当我现在尝试插入新记录时出现的异常是:
在“System.Data.SQLite.SQLiteFactory”类型的存储提供程序实例上调用“GetService”方法后,返回 null。商店提供商可能无法正常运行。
必须添加:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
到我的应用程序配置文件。现在看起来像:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>
在安装 sqlite 的位置我必须复制
到我的程序 exe 所在的输出目录
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)