从Web服务连接到数据库的连接字符串 [英] Connection string to connect to Database from Web Service

查看:85
本文介绍了从Web服务连接到数据库的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的连接字符串,Web服务(托管在IIS中)用于连接到数据库

This is my connection string, which the web service (hosted in IIS) uses to connect to database

<add name="AdventureWorksEntities"connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
provider=System.Data.SqlClient;provider connection string='Data Source=TestMachine;Initial Catalog=AdventureWorks;
Integrated Security=True;Connection Timeout=60;multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />



当我尝试访问该网站时,出现异常:用户MyDomain \ TestMachine $登录失败.

IIS为什么要尝试使用TestMachine而不是我的用户帐户(例如MyDomain \ TestUser)进行连接?如何指定它以使用发出请求的用户的上下文?



When I try to access the site I am getting an exception: Login Failed for user MyDomain\TestMachine$.

Why is IIS trying to use TestMachine to connect and not my user account (e.g MyDomain\TestUser) ? How do I specify it to use the context of the user that made the request ?

推荐答案

.

IIS为什么要尝试使用TestMachine而不是我的用户帐户(例如MyDomain \ TestUser)进行连接?我如何指定它以使用发出请求的用户的上下文?
.

Why is IIS trying to use TestMachine to connect and not my user account (e.g MyDomain\TestUser) ? How do I specify it to use the context of the user that made the request ?


您必须在web.config中启用模拟".这将使IIS在连接到SQL时使用您的Windows帐户.


< system.web>
< identity impersonate ="true"/>
....</system.web>
You have to turn on Impersonation in the web.config. This will make IIS use your windows account when connecting to SQL


<system.web>
<identity impersonate="true" />
....</system.web>


如果您使用Windows身份验证,即使是远程也可以使用.
It will work if you use Windows Authentication, even remotely.


这篇关于从Web服务连接到数据库的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆