亲而有间,密而有疏;和而不同,美美与共

(ADO.NET)关于C#中“配置”sqlite问题

配置打引号,只是因为觉得只是一些小问题,在此记录一下,第一次遇到还真有点手足无措,昨天到今天~终于可以开始放肆的写sqlite了。

好,第一个问题是引用已下载的system.data.sqlite.dll 出现警告,一开始没在意,才导致找不到下一个问题的原因。

警告 1 所生成项目的处理器架构“MSIL”与引用“System.Data.SQLite”的处理器架构“x86”不匹配。这种不匹配可能会导致运行时失败。请考虑通过配置管理器更改您的项目的目标处理器架构

去除这个警告,只要在解决方案,右击,属性,生成,把anycpu改为X86,即OK!

第二个问题是运行sqlite语句,如连接

using (SQLiteConnection con = new SQLiteConnection(ConnStr))
{
con.Open();
using (SQLiteCommand com = new SQLiteCommand())
{
com.Connection = con;
com.CommandText = "insert into T_Login values('2015','2015')";
com.ExecuteNonQuery();
}
}

则会出现:“System.IO.FileLoadException”类型的未经处理的异常在 PresentationCore.dll

解决方法:

Paste the following XML inside the configuration tag:

  <startup useLegacyV2RuntimeActivationPolicy="true">     <supportedRuntime version="v4.0"/>   </startup>

其实只要往原有的<startup>标签中加入useLegacyV2RuntimeActivationPolicy="true" 即OK。

 

sqlite连接语句:最简单的,直接给个路径 string ConnStr = @"Data Source=C:\\zhj.db";

在configuration tag 中: 

<connectionStrings>
<add name="dbConnStr" connectionString="Data Source=C:\\zhj.db;Pooling=true;FailIfMissing=false"/>
</connectionStrings>

在SQLiteHelper.cs里调用:

string ConnStr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;

当然,要引用System.Configuration;

posted @ 2015-07-18 13:52  大兄弟竹子  阅读(514)  评论(0编辑  收藏  举报