0

I have created an ASP.NET MVC 3 application and I have in the DAL an ADO.NET entity data model with classes to access data too.

I also have a WCF restful service that I created for communication with my android app. So when I tried to host my service on IIS7 I got this error:

The underlying provider failed on Open and here :

The server encountered an error processing the request. The exception message is 'The underlying provider failed on Open.'. See server logs for more details. The exception stack trace is at

System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) at System.Data.EntityClient.EntityConnection.Open() at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) at SecurityLayer.Authentification.Auth.VerifAuth(User u) in c:\Users\ines\Documents\Visual Studio 2012\Projects\GestionDeComptabilite\ControleLayer\Authentification\Auth.cs:line 16 at ManagementServices.AllServices.Authentification(String pseudo, String password) in c:\Users\ines\Documents\Visual Studio 2012\Projects\GestionDeComptabilite\ManagementServices\AllServices.svc.cs:line 28 at SyncInvokeAuthentification(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at 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)

For a side note, my WCF service has no problem when I launch it from Visual Studio, the problem is only with IIS. When I searched for this problem I tried these things which where proposed as solutions :

  • delete integrated security from the connection string
  • use sql authentification
  • make an account and grant it access to the data base and make sure the app in iis have access to the data base
  • added all the composants of the "Application Development Features" except CGI

I also tried all the solution proposed in those links still none of them worked:

MSSQL Error 'The underlying provider failed on Open'

and this one too:

Entity Exception : the underlying provider failed to open

If anyone can help I'd appreciate it a lot.

For more information here's my code:

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>

Please note that it's a WCF restful APPLICATION and not a library, I am also running under Windows 7 Ultimate 64 bit in VirtualBox.

Community
  • 1
  • 1

1 Answers1

0

Need your confirmation...., You use mdf file in your connection string, where is your IIS server, is it on same machine where you ran app with Visual Studio.?

If you host on different physical box then full path exist with .mdf file..... Below is portion of connection string from your shared web.config, you should verify the exitance of file first..... data source=(localDB)\v11.0;attachdbfilename=C:\Users\ines\Documents\Visual Studio 2012\Projects\GestionDeComptabilite\DataRepository\App_Data\GestionComptabilite.mdf;MultipleActiveResultSets=True;App=EntityFramework"

Hi10
  • 531
  • 1
  • 5
  • 21