(1) 從下面的網(wǎng)址下載了 SQLite 版本(sqlite-netFx40-setup-bundle-x64-2010-1.0.83.0):
http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
安 .cs 文件中使用了 using:using System.Data.SQLite;
增加代碼:SQLiteConnection.CreateFile(dataSource); 運(yùn)行時(shí)報(bào)錯(cuò)如下(第一次使用C#,請(qǐng)各位幫忙分析一下出錯(cuò)的原因):
未處理 System.BadImageFormatException
? Message=未能加載文件或程序集“System.Data.SQLite, Version=1.0.83.0, Culture=neutral,?
PublicKeyToken=db937bc2d44ff139”或它的某一個(gè)依賴項(xiàng)。試圖加載格式不正確的程序。
? Source=UseSQLite
? FileName=System.Data.SQLite, Version=1.0.83.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
? FusionLog==== 預(yù)綁定狀態(tài)信息 ===
日志: 用戶 = yonghang-PCyonghang
日志: DisplayName = System.Data.SQLite, Version=1.0.83.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
?(Fully-
specified)
日志: Appbase = file:///E:/Source/PC/UseSQLite/bin/Debug/
日志: 初始 PrivatePath = NULL
調(diào)用程序集: UseSQLite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null。
===
日志: 此綁定從 default 加載上下文開始。
日志: 未找到應(yīng)用程序配置文件。
日志: 使用主機(jī)配置文件:?
日志: 使用 C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config 的計(jì)算機(jī)配置文件。
日志: 策略后引用: System.Data.SQLite, Version=1.0.83.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
日志: 嘗試下載新的 URL file:///E:/Source/PC/UseSQLite/bin/Debug/System.Data.SQLite.DLL。
錯(cuò)誤: 未能完成程序集的安裝(hr = 0x8007000b)。探測(cè)終止。
? StackTrace:
? ? ? ?在 UseSQLite.Form1.CreateSqliteDatabase()
? ? ? ?在 UseSQLite.Form1..ctor() 位置 E:SourcePCUseSQLiteForm1.cs:行號(hào) 22
? ? ? ?在 UseSQLite.Program.Main() 位置 E:SourcePCUseSQLiteProgram.cs:行號(hào) 18
? ? ? ?在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
? ? ? ?在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
? ? ? ?在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
? ? ? ?在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
? ? ? ?在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object?
state, Boolean ignoreSyncCtx)
? ? ? ?在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object?
state)
? ? ? ?在 System.Threading.ThreadHelper.ThreadStart()
? InnerException:?
代碼:
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
?
using?System.Data.SQLite;
?
namespace?UseSQLite
{
????public?partial?class?Form1?:?Form
????{
????????private?string?dataSource?=?"UseSQLite.sqlite";
????????//private?string?dataSource?=?"E:/Source/PC/SQliteDB.db";
?
????????public?Form1()
????????{
????????????InitializeComponent();
?
????????????CreateSqliteDatabase();
????????}
?
????????void?CreateSqliteDatabase()
????????{
????????????System.Diagnostics.Debug.WriteLine("Use?SQLite:?start?create?database...");
????????????SQLiteConnection.CreateFile(dataSource);
//?????????????SQLiteConnection?conn?=?new?SQLiteConnection();
//?????????????SQLiteConnectionStringBuilder?connstr?=?new?SQLiteConnectionStringBuilder();
//?????????????connstr.DataSource?=?dataSource;
//?????????????connstr.Password?=?"admin";?//設(shè)置密碼,SQLite?ADO.NET實(shí)現(xiàn)了數(shù)據(jù)庫密碼保護(hù)
//?????????????conn.ConnectionString?=?connstr.ToString();
//?????????????conn.Open();
????????????System.Diagnostics.Debug.WriteLine("Use?SQLite:?create?database?end.");
????????}
????}
}
CSDN友回復(fù)可能是因?yàn)橐韵略颍?br />有可能是框架配置不正確,SQLite是.NET 4.0,而你的控制臺(tái)為.NET 4.0 Client Profile;
.NET 4.0 大于 .NET 4.0 Client Profile 查看項(xiàng)目屬性,更改試試.
?.NET 4.0 Client Profile比.NET 4.0占用的空間要小,但支持的類型也比.NET 4.0支持的類型小。
SQLITE的動(dòng)態(tài)庫是.NET 4.0 Client Profile不支持的。
未驗(yàn)證是否是這樣。
(2) 下載了:SQLite-1.0.66.0-setup.exe,安裝后在 VS2010 的菜單“增加新數(shù)據(jù)源”的“新建連接...”中終于找到了 SQLite 的選項(xiàng)。
然后需要將工程的目標(biāo)框架由 4.0 修改為 3.5,否則編譯報(bào)錯(cuò)。
最后,在工程中“增加引用”,選擇 SQLite.NETbin 目錄的:System.Data.SQLite.dll和System.Data.SQLite.dll(可選)
(3) 創(chuàng)建數(shù)據(jù)庫
......





