SQL integrated security using computer name instead of user name

元气小坏坏 提交于 2019-12-18 11:22:08

问题


I am trying to an SQL Express instance on the same network, authenticating with my domain user. It works just fine with Windows Authentication in SSMS. I verified that I can use the MyDB database, including editing tables.

However, when I try the following connection string:

Server=ipaddress\SQLExpress; Database=MyDB; Integrated Security=SSPI;

I get back an error:

Cannot open database "MyDB" requested by the login. The login failed. Login failed for user 'ROMANIA\MONSTER2$'

The problem is that MONSTER2 is the name of my computer, not my username. (ROMANIA is the domain.) What am I doing wrong?

[Edit] I forgot something that might be relevant: I am trying to open the connection from a webservice running on my computer.


回答1:


Your web service is running under the NT AUTHORITY\Network Service security context. This will cause the process to use the host's machine account when accessing network resources in the domain.

You'll have to configure the web service to run with your domain identity.

If you're hosting your web service in IIS, you can do this through impersonation. Here's an example:

<configuration>
    <system.web>
        <identity
            impersonate="true"
            userName="ROMANIA\username" 
            password="********" />
    </system.web>
</configuration>



回答2:


That is because your web server is not set up to use the identity of the person using the service, but rather the identity of the computer it is running on.

Check if your web.config for the web service contains: <authentication mode="Windows" />




回答3:


I needed to do both in my situation:

<authentication mode="Windows" />
    <authorization>
        <deny users="?" />
    </authorization>
<identity impersonate="true" />


来源:https://stackoverflow.com/questions/6761596/sql-integrated-security-using-computer-name-instead-of-user-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!