[英]Error when connecting to a SQL database: Cannot open database “Students.mdf” requested by the login. The login failed
[英]login failed error when connecting to database from WCF service
我創建了WCF服務,其中一種方法連接到數據庫以執行某些任務。 當我從客戶端(網站或控制台應用程序)調用WCF服務方法時,出現登錄失敗錯誤(“登錄失敗”,登錄來自不受信任的域”)。我可以從網站成功連接到數據庫,但是當我通過調用WCF服務並從該服務連接到同一數據庫來執行相同操作時,出現此錯誤。這與客戶端配置有關嗎?我使用svcutil實用程序創建了客戶端,並使用了它生成的相同客戶端配置。外觀如何,請幫助。在開發環境中,它應該使用我的帳戶連接到數據庫,一旦部署到測試環境中,就應該使用在IIS應用程序池中為WCF服務配置的服務帳戶。 。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/WcfService/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="IService1" name="BasicHttpBinding_IService1" />
</client>
您的clientCredentialType是“ Windows”,我懷疑WCF服務正在使用委派,也就是說,該服務正在使用來自客戶端的用戶憑據來嘗試與數據庫對話。 換句話說,如果客戶端應用程序在Windows框上運行,且登錄用戶為DomainA \\ SomeUser,則服務中的憑據將為DomainA \\ SomeUser,而不是IIS應用程序池中配置的帳戶。 該鏈接應該能夠使您運行: Wcf模擬
當我從客戶端(網站或控制台應用程序)調用WCF服務方法時,出現登錄失敗錯誤(“登錄失敗”,登錄來自不受信任的域”)。我可以從網站成功連接到數據庫,但是當我通過調用WCF服務並從該服務連接到同一數據庫來執行相同操作時,出現此錯誤
我之所以一般回答是因為您的問題是抽象的-沒有操作系統,IIS,SQL Server版本/版本/模式,沒有有關配置的詳細信息,錯誤等。
這是經典的“雙跳”問題。 您可能還想知道模擬(僅在本地使用)與委托(用於連接到另一台計算機)之間的區別。 您應該在生產服務器中配置委派的信任(可能是SPN-服務主體名稱),並相應地對應用程序進行編碼。
請通過關鍵字“雙跳”,“ IIS,SQL Server”,模擬,委派,asp.net,身份驗證,信任,部署來搜索Internet。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.