技术笔记_如何在vs2015中配置使用sqlite3 x64 for .Net4x,vs2015sqlite3
1.首先在http://www.sqlite.org/download.html上根据需要的.net版本下载对应的sqlite程序集,有两种配置bundle或非bundle版本,推荐下载bundle版本的安装程序;
2.运行下载安装程序,该程序实际只是将对应的程序集复制到指定目录而已,虽然在安装过程中可以选择安装到GAC,但不推荐如此,一般也不需要;
3.复制到的目录下有若干测试程序:test.exe,testef6.exe,testlinq.exe,可以运行测试,特别是test.exe,如果没有问题说明下载的程序集没有问题;
下面vs2015下新建项目使用sqlite:
1.新建一个项目,比如控制台;
2.添加对System.Data.SQLite.dll(在下载的目录下)的引用;
3.修改项目的.config文件,增加如下内容:
<configuration>
...
<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>
这里实际是指定data provider的工厂接口.
4.重要:在项目属性页的“生成”页面,不要勾选“首选32位"!
然后测试以下代码,运行通过表明可以正常使用:
var factory = DbProviderFactories.GetFactory("System.Data.SQLite");
using (var connection = factory.CreateConnection())
{
connection.ConnectionString = "Data Source=<你的sqlite数据库>";
connection.Open();
}
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。