關於sqlite資料庫在使用過程中應該注意以下幾點

來源:互聯網
上載者:User

 

1:使用sqlite資料庫,經常會出現資料庫連接不上的情況,這個時候需要檢查sqlite.dll是否添加了引用,且添加的dll的版本與所使用的sqlite版本是否一致。

   這兩個dll是使用sqlite必須要添加的引用,

 

2:為了不使sqlite發布後,找不到資料庫,需要手動設定這兩個dll自動拷貝到本地。

                右擊-》屬性-》

 

3:發布的網站記得在Web.config 檔案下添加以下節點才能正確訪問到sqlite資料庫

 <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>

4:資料庫放在app_data目錄下,發布時引用檔案的地址為,不至於是絕對路徑無法訪問:

<connectionStrings>
  <add name="dbEntities" connectionString="metadata=res://*/Models.DBModel.csdl|res://*/Models.DBModel.ssdl|res://*/Models.DBModel.msl;provider=System.Data.SQLite;provider connection string=&quot;data source=|DataDirectory|\db.db&quot;" providerName="System.Data.EntityClient" />
 </connectionStrings>

 

5:今天配置一台x64的機器時,報sqlite的錯誤,“Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. 試圖載入格式不正確的程式。”

一開始總以為是sqlite資料庫連接不上或是dll版本的問題,後來才發現,System.Data.SQLite是分了作業系統版本的,有X86,X64之分;因此應用程式集區應該選擇相容WIN32;

錯誤:

具體操作如下:
在iis管理器,選中應用程式集區-》對正在使用的應用程式集區 點擊 進階設定   -》啟用32位應用程式 為 true.

 

這時重新整理頁面  錯誤解除。

 

 

 

 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.