2013-03-29 65 views
0

目前我正在部署WCF服務,實體框架訪問sqlite數據庫。該服務託管在窗口服務下。部署完成後,該服務已創建。我可以從其他機器訪問WSDL頁面。但是,我無法通過EF從數據庫獲取數據。當它處於開發環境時,所有工作。在部署到其他macgine之後,當我使用相同的查詢時,它會引發錯誤:無法找到或加載已註冊的.Net Framework數據提供程序。用實體框架部署WCF服務的問題

我認爲這個問題會涉及到sqlite的東西。我在「遠程」機器上安裝了.NET Framework 4.5和System.data.SQLite,但我仍然無法工作。有誰知道這個問題的原因?感謝您提前提供任何幫助。

此外,我是否需要在代碼中初始化DbProviderFactory以便在app.config文件中使用它?如果是這樣,哪裏應該是適當的地方插入它們?

這裏是窗口服務我的app.config文件:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <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.84.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /> 
    </DbProviderFactories> 
    </system.data> 
    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="ServBehave" name="iPhysio_Wcf_Service.Service"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://86.163.77.253:8733/iPhysio_Wcf_Service/Service/" /> 
      </baseAddresses> 
     </host> 
     <endpoint address="soapService" binding="basicHttpBinding" contract="iPhysio_Wcf_Service.IService" /> 
     <endpoint address="XMLService" behaviorConfiguration="restPoxBehavior" binding="webHttpBinding" contract="iPhysio_Wcf_Service.IService" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServBehave"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <!--Behavior for the REST endpoint for Help enability--> 
     <behavior name="restPoxBehavior"> 
      <webHttp helpEnabled="true" /> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    </system.serviceModel> 
    <connectionStrings> 
    <add name="iPhysioAndroidDBEntities1" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:\Users\SiuWai\Desktop\iPhysioAndroidDB&quot;'" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
</configuration> 
+0

您是否在另一臺機器上安裝了SQLite的相同版本1.0.84.0?你也可以嘗試從這裏的解決方案:http://stackoverflow.com/questions/1875134/c-sharp-failed-to-find-or-load-the-registered-net-data-provider-error –

+0

我試過這個解決方案,它不起作用。 –

+0

你已經嘗試了這個解決方案,並且檢查了'System.Data.SQLite.dll'在遠程機器上的解決方案的'bin'文件夾中? (也許'msvcr100.dll'以及另一個答案中提到的那樣。) –

回答

1

我不知道這是否是它,但在配置您的連接字符串:

connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:\Users\SiuWai\Desktop\iPhysioAndroidDB&quot;'" 

似乎是引用C:\ Users的位置。這是SQLite數據庫在遠程服務器上的部署位置嗎?

除此之外,<system.data>部分的DbProviderFactories東西看起來對我來說還不錯,我不認爲那裏有什麼錯誤(或者有什麼不同於網上關於如何做到這一點的文獻)......對不起,沒有在.NET中使用SQLite的專家 - 我只是天真地做了幾次例子/學習。

+0

由於SQLITE數據庫和窗口服務下託管的WCF服務位於同一遠程計算機中。所以我認爲在同一臺機器上引用數據庫就像這樣使用C:\ Users是好的。這是對的嗎?如果不正確,你有任何提示嗎? –

+0

@CharlesLAU如果該路徑下的_remote machine_上的該文件夾和SQLite數據庫_存在_,那麼它應該可能工作。但請記住,WCF服務可能會以用戶網絡服務而不是您自己的身份訪問該文件,因此您需要爲該文件設置模擬或權限。 –

+1

同意。我還建議讓C:\ Users下的數據庫可能不是最好的地方(考慮到你會知道它在哪裏,但其他人可能不會維護或處理你的代碼庫) 。是否有可能把它放在像'C:\ SqlLiteDb'這樣比較常見的地方,或者是某種與特定用戶無關的地方?另外,我注意到你的連接字符串沒有'.s3db'擴展名,但不知道是否這個問題.... – nkvu