System.Data.EntityException: The underlying provider failed on Open.


場景: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>
View Code

  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"]);
            }
        }
View Code

  或者配置文件直接寫

<appSettings>
    <add key="CupCreditCheckDB" value="metadata=res://*/CupModel.csdl|res://*/CupModel.ssdl|res://*/CupModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Server=fscnbesd0001;Database=CreditCheckGateway;Integrated Security=SSPI&quot;" providerName="System.Data.EntityClient" />
</appSettings>
View Code

 

 <connectionStrings>
    <add name="CupCreditCheckDB" connectionString="metadata=res://*/CupModel.csdl|res://*/CupModel.ssdl|res://*/CupModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Server=fscnbesd0001;Database=CreditCheckGateway;Integrated Security=SSPI&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
View Code

 

 

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM