最近作了一個小應用,使用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:ide
<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 spa
根據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了,說明配置沒有問題了。.net
可是運行程序,仍是報錯:「對類型"System.Data.SQLite.SQLiteFactory"的存儲區提供程序調用"GetService"方法後,返回null。存儲區提供程序可能未正常運行」。blog
花了一段時間研究「存儲區」,無功而返。ip
忽然發現生產環境的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,運行程序:一切正常!大功告成!rem