C#连接Sqlite 出现:
混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。的解决方案
C#连接sqlite数据库代码:
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Data.SQLite;
6 using System.Drawing;
7 using System.Linq;
8 using System.Text;
9 using System.Threading.Tasks;
10 using System.Windows.Forms;
11
12 namespace T_W_sqlite
13 {
14 public partial class Form1 : Form
15 {
16 public static SQLiteConnection sqlConn;
17 public static string ConnectionString = "Data Source=E://Test.db3;Pooling=true;FailIfMissing=true";//存储公用的数据库连接字符串
18
19 public static String StartSQLConn()
20 {
21 sqlConn = new SQLiteConnection(ConnectionString);
22 try
23 {
24 sqlConn.Open();
25 }
26 catch
27 {
28 sqlConn = null;
29 }
30 return "You Test Success!";
31 }
32 public Form1()
33 {
34 InitializeComponent();
35 Lable.Text = StartSQLConn();
36
37 }
38 }
39 }
解决方法:
解决方案中找到App.config 文件
在app.config的configuration节点下添加:
原始为:
1 <?xml version="1.0" encoding="utf-8" ?>
2 <configuration>
3 <startup>
4 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5 </startup>
6 </configuration>
修改为:
1 <?xml version="1.0" encoding="utf-8" ?>
2 <configuration>
3 <startup useLegacyV2RuntimeActivationPolicy="true">
4 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5 </startup>
6 </configuration>
便可解决上述问题.
By HRuinger.
|