2013-03-29 67 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