c# - Entity Framework : The underlying provider failed on Open - through WCF service

标签 c# .net wcf entity-framework iis

我有一个在 IIS 上运行的 WCF 服务,但它无法访问在同一台计算机上运行的 SQL Server。如果我使用 WCF 测试客户端,它工作正常。可能是什么问题?谢谢!

服务的 web.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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding></wsDualHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="wsDualHttpBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="TestEntities" connectionString="metadata=res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=Test;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

最佳答案

您运行 WCF 服务的应用程序池用户可能没有访问 SQL 数据库的权限。您可以将自己添加为用户或为当前应用程序池用户分配权限。

类似的问题 How to use domain windows user account as app pool identity

关于c# - Entity Framework : The underlying provider failed on Open - through WCF service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22798811/

相关文章:

c# - 如何删除未选择的 TreeView 节点

c# - 编译错误集合被修改

c# - IList 必须是有限的吗?

c# - 如何在 WCF 服务中将接口(interface)作为参数传递?

c# - 基于字典的字符串操作

c# - 如何将 xml 文件复制到文件夹中并隐藏它?

c# - 如何在服务器 app.config 中保存动态端点?

wcf - 将数据发布到 JSONP

.net - 如何让 ASP.NET 输出 UTF-16 编码的文本?

c# - 高效的异常处理技术