我有a .NET 4.5 application,它已经启动并运行。此应用程序可以连接到SQL Server和MS Access数据库文件。
现在,我想使用一个SQLite数据库。
因此,我ADO.net从this link下载了SQLite www.example.com 4.5数据提供程序(sqlite-netFx 45-setup-x64-2012-1.0.117.0.exe),并将其安装在我的笔记本电脑上。
我的连接字符串如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="assemblies" type="Simple.Framework.AssembliesConfigurationSection, Simple.Framework"/>
</configSections>
<connectionStrings>
<!--<add name="MyMSAccessConnStr"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DB\access_db_file.mdb;Persist Security Info=False"
providerName="System.Data.OleDb"/>-->
<!--<add name="MySQLServerConnStr" connectionString="Data Source=.\sqlexpress;Initial Catalog=gre;Integrated Security=True"
providerName="System.Data.SqlClient"/>-->
<add name="MySQLiteConnStr" connectionString="Data Source=C:\DB\sqlite_db_file.db;Version=3;"
providerName="System.Data.SQLite"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
</configuration>
在上面的例子中,MyMSAccessConnStr
和MySqlServerConnStr
已经可以正常工作了。
然而,SQLite连接不起作用。它给出以下错误:
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: Unable to find the requested .Net Framework Data Provider.
It may not be installed.
我在GAC中也没有看到System.Data.Sqlite
。
如何解决此问题?
2条答案
按热度按时间k2fxgqgv1#
发生此错误的原因是您的系统不知道
System.Data.SQLite
ADO.Net数据库访问接口。您可以自己在GAC中安装它,并在machine.config中声明它,如下所述:Obtaining a DbProviderFactory
但是你don't need to install it in the GAC:
app.config
中声明如下:System.Data.SQLite.dll
和SQLite.Interop.dll
复制到QuizApplication.exe
文件旁边即可。8fsztsew2#
确保在<system.data>配置中包含该元素:
另外,请确保在构建/调试/发布时将SQLite dll复制到输出目录(通常是bin文件夹):Example