场景:IIS默认站点建立程序,使用Windows集成身份验证方式,连接SQLServer数据库也是采用集成身份验证。我报“System.Data.EntityException: The underlying provider failed on Open.”这个错误是因为计算机登录密码改过,导致之前应用程序池设置的凭证错误,解决办法:把应用程序池的登录凭证也修改一下改成和计算机登录密码一样,这样程序就好了。
步骤:
新增一个应用程序:
IIS Default Web Site-->Add Application-->Application Pool-->ASP.NET V4.0 Integrated
修改应用程序池的凭证:
Application Pool-->ASP.NET V4.0 Integrated-->Advanced Settings-->Process Model-->Identity-->Customer account-->Set Credentials-->Set UserName=Cumputer LoginName,Password=Cumputer Login Password-->Click OK
配置文件
<appSettings> <add key="CreditCheckGatewayDB" value="Server=fscnbesd0001;Database=CreditCheckGateway;Integrated Security=SSPI;" /> </appSettings>
C#读取连接字符串
static public string GetCupCreditCheckConnectionString { get { return string.Format("metadata=res://*/CupModel.csdl|res://*/CupModel.ssdl|res://*/CupModel.msl;provider=System.Data.SqlClient;provider connection string=\"{0}\";", ConfigurationManager.AppSettings["CreditCheckGatewayDB"]); } }
或者配置文件直接写
<appSettings> <add key="CupCreditCheckDB" value="metadata=res://*/CupModel.csdl|res://*/CupModel.ssdl|res://*/CupModel.msl;provider=System.Data.SqlClient;provider connection string="Server=fscnbesd0001;Database=CreditCheckGateway;Integrated Security=SSPI"" providerName="System.Data.EntityClient" /> </appSettings>
<connectionStrings> <add name="CupCreditCheckDB" connectionString="metadata=res://*/CupModel.csdl|res://*/CupModel.ssdl|res://*/CupModel.msl;provider=System.Data.SqlClient;provider connection string="Server=fscnbesd0001;Database=CreditCheckGateway;Integrated Security=SSPI"" providerName="System.Data.EntityClient" /> </connectionStrings>