基础提供程序在iis7中的wcf中出现Open异常时失败
本文关键字:Open 异常 失败 wcf 中的 程序 iis7 | 更新日期: 2023-09-27 18:29:54
我创建了一个ASP.NET MVC 3应用程序,并且在DAL中有一个ADO.NET实体数据模型,其中也包含访问数据的类。
我还创建了一个WCF restful服务,用于与我的android应用程序进行通信。所以当我试图在IIS7上托管我的服务时,我得到了这个错误:
基础提供程序在Open和此处失败:
服务器在处理请求时遇到错误。异常消息为"基础提供程序在打开时失败。"。有关详细信息,请参阅服务器日志。异常堆栈跟踪位于
System.Data.EntityClient.EntityConnection.OOpenStoreConnectionIf(布尔值openCondition,DbConnection storeConnectionToOpen,DbConnectionoriginalConnection,String exceptionCode,String attemptedOperation,布尔运算&closeStoreConnectionOnFailure)位于的System.Data.EntityClient.EntityConnection.Open()位于的System.Data.Objects.ObjectContext.EnsureConnection()System.Data.Objects.ObjectQuery
1.GetResults(Nullable
1forMergeOption)System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1source)在System.Linq.Queryable.FirstOrDefault[TSource](IQueryable `1源)的SecurityLayer.Authentification.Auth.VerifAuth(用户u)c: ''Users''ines''Documents''Visual Studio2012''Projects''GestionDeCompabilite''ControlLayer''Authentification''Auth.cs:line16在ManagementServices.AllServices.Authentication(字符串伪,字符串密码)2012''Projects''GestionDeComptabilie''ManagementServices''AllServices.svc.cs:line28在的SyncInvokeAuthentification(Object,Object[],Object[])System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(对象实例,Object[]输入,Object[]&输出)System.ServiceModel.Dispatcher.DispatchOperationRuntime.IInvokeBegin(MessageRpc&rpc)System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&rpc)System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&rpc)在System.ServiceModel.Dispatcher.MessageRpc.Process(布尔isOperationContextSet)
附带说明一下,当我从Visual Studio启动WCF服务时,它没有问题,问题仅在于IIS。当我搜索这个问题时,我尝试了这些建议作为解决方案的东西:
- 从连接字符串中删除集成安全性
- 使用sql身份验证
- 创建一个帐户并授予其访问数据库的权限,并确保iis中的应用程序可以访问数据库
- 添加了除CGI之外的"应用程序开发特性"的所有组成部分
我还尝试了在这些链接中提出的所有解决方案,但都不起作用:
MSSQL错误';基础提供程序在打开';
还有这个:
实体异常:基础提供程序无法打开
如果有人能帮忙,我将不胜感激。
更多信息,这里是我的代码:
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="data source=(localDB)'v11.0;attachdbfilename=C:'Users'ines'Documents'Visual Studio 2012'Projects'GestionDeComptabilite'DataRepository'App_Data'GestionComptabilite.mdf;MultipleActiveResultSets=True;App=EntityFramework"" 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应用程序,而不是一个库,我也在VirtualBox中的Windows 7 Ultimate 64位下运行。
需要您的确认。。。。,您在连接字符串中使用mdf文件,IIS服务器在哪里,它是否在您使用Visual Studio运行应用程序的同一台计算机上。?
如果您托管在不同的物理盒上,则.mdf文件的完整路径存在。。。。。以下是共享web.config中连接字符串的一部分,您应该首先验证文件的存在性。。。。。数据源=(localDB)''v11.0;attachdbfilename=C:''Users''ines''Documents''Visual Studio 2012''Projects''GestionDeComptabilie''DataRepository''App_Data''GestionComptabilie.mdf;MultipleActiveResultSets=True;App=EntityFramework";