SQLite to Asp.net Entity Framework 部署問題

來源:互聯網
上載者:User
最近做了一個小應用,使用SQLite做資料庫。開始用DBLINQ的時候,做一個LINQ查詢出現不支援的問題。後來看到Entity Framework是可以支援SQLite的,於是很快轉換過來。完成開發,在開發機器上測試正常。部署到正式環境中,開始出現“指定的儲存區提供者在配置中找不到,或者無效。”----> "找不請求的.Net Framework資料提供者。可能沒有安裝”。

這個問題出現的很奇怪,因為生產機器上也運行了SQlite.net 的安裝包。
運行了一個測試程式,輸出 DbProviderFactories.GetFactoryClasses()的DataTable,發現生產環境的Data Provider的確沒有SQLite這一項。

在網上查了一圈,發現有人提示:

1. Add the following to the Web.config file:

<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,
Version=1.0.57.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"
/>
    </DbProviderFactories>
  </system.data>

 2. Copy System.Data.SQLite.DLL AND System.Data.SQLite.Linq.dll files to the Bin directory

根據1 的提示,我把
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite,
Version=1.0.57.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"
/>這段配置,也加到生產環境的Machine.config裡面,再運行測試程式,SQLite項出現在DbProviderFactories.GetFactoryClasses()的DataTable了,說明配置沒有問題了。

但是運行程式,還是報錯:“對類型"System.Data.SQLite.SQLiteFactory"的儲存區提供者調用"GetService"方法後,返回null。儲存區提供者可能未正常運行”。

花了一段時間研究“儲存區”,無功而返。

突然發現生產環境的GAC沒有System.Data.SQLite,問題是不是在這裡呢?

在生產環境下v1.1.xxx下的GacUtil.exe運行之後,報錯unknown。又在網上查了一下,據說是GacUtil和Framework的版本有關係。在開發機器上C:/Program Files/Microsoft SDKs/Windows/v6.0A/Bin找到一個GacUtil.exe,一看,的確這個是3.5的版本。拷貝到生產環境,註冊System.Data.SQLite.DLL和System.Data.SQLite.Linq.DLL,運行程式:一切正常!大功告成!

最後總結問題所在,有兩點:

1 GAC沒有註冊 System.Data.SQLite.DLL和System.Data.SQLite.Linq.DLL

2 Machine.config的DBProviderFactories沒有正確增加SQLite相關項目。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.