基础提供程序在iis7中的wcf中的Open异常失败

时间:2013-09-02 21:54:07

标签: c# asp.net wcf iis

我创建了一个ASP.NET MVC 3应用程序,我在DAL中有一个ADO.NET实体数据模型,其中包含用于访问数据的类。

我还有一个WCF restful服务,我创建用于与我的Android应用程序进行通信。因此,当我尝试在IIS7上托管我的服务时,我收到了这个错误:

  

底层提供程序在Open上失败,在这里:

     

服务器在处理请求时遇到错误。异常消息是“基础提供程序在打开时失败”。请参阅服务器日志以获取更多详异常堆栈跟踪位于

     

System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(布尔   openCondition,DbConnection storeConnectionToOpen,DbConnection   originalConnection,String exceptionCode,String attemptsOperation,   布尔和放大器; closeStoreConnectionOnFailure)at   System.Data.EntityClient.EntityConnection.Open()at   System.Data.Objects.ObjectContext.EnsureConnection()at   System.Data.Objects.ObjectQuery 1.GetResults(Nullable 1   forMergeOption)at   System.Data.Objects.ObjectQuery 1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable 1   System.Linq.Queryable.FirstOrDefault [TSource](IQueryable`1)   来自SecurityLayer.Authentification.Auth.VerifAuth(用户u)in   c:\ Users \ ines \ Documents \ Visual Studio   2012 \项目\ GestionDeComptabilite \ ControleLayer \身份认证\ Auth.cs:行   16在ManagementServices.AllServices.Authentification(String伪,   字符串密码)在c:\ Users \ ines \ Documents \ Visual Studio中   2012 \项目\ GestionDeComptabilite \ ManagementServices \ AllServices.svc.cs:行   28在SyncInvokeAuthentification(Object,Object [],Object [])at   System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(对象   实例,对象[]输入,对象[]&amp;输出)   System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&安培;   rpc)at   System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&安培;   rpc)at   System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&安培;   rpc)at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean   isOperationContextSet)

对于旁注,当我从Visual Studio启动它时,我的WCF服务没有问题,问题仅在于IIS。当我搜索这个问题时,我尝试了这些提出解决方案的东西:

  • 从连接字符串中删除集成安全性
  • 使用sql authentification
  • 创建一个帐户并授予其访问数据库的权限,并确保iis中的应用程序可以访问数据库
  • 添加了除“CGI”之外的“应用程序开发功能”的所有组成者

我也尝试过在这些链接中提出的所有解决方案仍然没有工作:

  

MSSQL Error 'The underlying provider failed on Open'

也是这个:

  

Entity Exception : the underlying provider failed to open

如果有人可以提供帮助,我会非常感激。

有关详细信息,请参阅我的代码:

using SecurityLayer.Authentification;
using DataRepository.DAL;
using DataRepository.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;

namespace ManagementServices
{        
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class AllServices : IAllServices
    {
        public bool Authentification(string pseudo, string password)
        {           
            User u = new User
            {
                UserName = pseudo,
                Password = password
            };
            Auth a = new Auth() ;
            if (a.VerifAuth(u)) return true;
            return false;
        }
    }
}




using System;   
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace ManagementServices
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IAllServices" in both code and config file together.
    [ServiceContract(Namespace="http://Services.Compta.com")]
    public interface IAllServices
    {
        [OperationContract(Name="Authentification" )]     
        [WebInvoke(UriTemplate = "/Auth/{pseudo}/{password}", Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]       
        bool Authentification(string pseudo, string password);
    }
}


 <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />  <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" />
      </system.webServer>
      <connectionStrings>
        <add name="GestionComptabiliteEntities" connectionString="metadata=res://*/Data.GestionComptabiliteModel.csdl|res://*/Data.GestionComptabiliteModel.ssdl|res://*/Data.GestionComptabiliteModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localDB)\v11.0;attachdbfilename=C:\Users\ines\Documents\Visual Studio 2012\Projects\GestionDeComptabilite\DataRepository\App_Data\GestionComptabilite.mdf;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />    <identity impersonate="true" />
      </system.web>   
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>  <binding name="NewBinding0" /> </basicHttpBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <standardEndpoints>
          <webHttpEndpoint>
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
          </webHttpEndpoint>
        </standardEndpoints>
        <services>
          <service name="ManagementServices.AllServices" behaviorConfiguration="restBehavior">
            <endpoint address="" behaviorConfiguration="a" binding="webHttpBinding" name="xml" contract="ManagementServices.IAllServices" />
            <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="" contract="ManagementServices.IAllServices" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="restBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors> <behavior name="a">   <webHttp /> </behavior> </endpointBehaviors>        </behaviors>     </system.serviceModel>
    </configuration>

请注意,它是WCF restful APPLICATION 而不是库,我也在VirtualBox中的Windows 7 Ultimate 64位下运行。

1 个答案:

答案 0 :(得分:0)

需要你的确认......, 您在连接字符串中使用mdf文件,IIS服务器在哪里,是否在您使用Visual Studio运行应用程序的同一台计算机上。?

如果你在不同的物理盒上托管,那么.mdf文件就存在完整路径.....下面是你共享web.config中连接字符串的一部分,你应该首先验证文件的退出..... data source =(localDB)\ v11.0; attachdbfilename = C:\ Users \ ines \ Documents \ Visual Studio 2012 \ Projects \ GestionDeComptabilite \ DataRepository \ App_Data \ GestionComptabilite.mdf; MultipleActiveResultSets = True; App = EntityFramework“