1. 程式人生 > >asp.net使用Sqlite資料庫的連線

asp.net使用Sqlite資料庫的連線

Sqlite的使用其實跟Access差不多,就是連線到一個單獨的檔案.要指定該資料庫的路.而Sqlite在asp.net中不像Access和Sqlserver那樣,因為ado.net中已經整合有oledb和Sql的驅動,但沒有Sqlite的驅動.在使用Sqlite時要在專案中加入兩個檔案,一個是dll(System.Data.SQLite.DLL)一個是xml(System.Data.SQLite.XML)檔案.
在web.config中寫入連線字串如下:
<appSettings>
   <add key="ConnectionString" value="DataBase/OSTeacherDataBase.dll"></add>
</appSettings>
我是把sqlite.dll(資料庫檔案)放在網站根目錄下.系統分三層,除了網站外,其他層都是程式集,分為Model,DAL,BLL,DBUtility和WEB五個資料夾.資料庫檔案放在WEB下面.
讀取該連線字串的CS程式碼如下:
//資料庫連線字串(web.config來配置)       
public static string connectionString = "UseUTF16Encoding=True;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("../"+
System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
在此要引入
using System.Web;
using System.Web.UI;名稱空間.