Login failed. The login is from an untrusted domain and cannot be used with Windows authentication

后端 未结 4 1841
北海茫月
北海茫月 2020-12-11 02:21

My webpages are on secured server (https), and I am trying to connect the SQL Server 2008 Database, which is normal server. I am writing connectionstring on page itself, no

相关标签:
4条回答
  • 2020-12-11 02:32

    For future googlers:

    If you do need Integrated Security and are getting this error it might be you're using a local account instead of a domain account.

    I came across this running Visual Studio locally and trying to connect to a database on another machine. A workaround was to run Visual Studio as a different user, the prompt didn't work but running the command below did (make sure to replace DOMAIN\USER and you will be asked to provide credentials):

    runas /netonly /user:DOMAIN\USER "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe"

    (This is for VS2019, your path may vary).

    0 讨论(0)
  • 2020-12-11 02:46

    I created a new Asp.Net Core MVC site and I had this same error. I was attempting to connect to my company's database while connected to the network via VPN. Here's what worked for me:

    Instead of

    "DevConnection": "Server=DevDBServer;Database=MyDatabase;User ID=some_userid;Password=some_password;Integrated Security=SSPI;Trusted_Connection=True;"
    

    I used

    "DevConnection": "Server=DevDBServer;Database=MyDatabase;User ID=some_userid;Password=some_password;Integrated Security=False;Trusted_Connection=False;"
    

    The key change was to make sure that Trusted_Connection=False, which is consistent with the error message. Generally I would not use an untrusted connection. In this case I was connecting to a dev/test database so it's fine.

    0 讨论(0)
  • 2020-12-11 02:50

    Old question, and my symptoms are slightly different, but same error. My connection string was correct (Integrated security, and I don't provide user and pwd) with data source set to 127.0.0.1. It worked fine for years.

    But recently I added a line in the static host file for testing purposes (C:\Windows\System32\drivers\etc\hosts)

    127.0.0.1           www.blablatestsite.com
    

    Removing this line and the error is gone.

    I got a clue from this article (https://support.microsoft.com/en-gb/kb/896861) which talks about hostnames and loopback.

    Other possible fix (if you need to keep that line in the hosts file) is to use the hostname (like MYSERVER01) instead of 127.0.0.1 in the data source of the connection string.

    0 讨论(0)
  • 2020-12-11 02:55

    Your connection string is telling it to use integrated security SSPI, which will use the Windows credentials.

    Set Integrated Security to false if you are going to be providing the username and password.

    Also, consider putting your connection string inside of the web.config file - it is more secure and reusable.

    From http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=VS.100).aspx:

    When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication. Recognized values are true, false, yes, no, and sspi (strongly recommended), which is equivalent to true. If User ID and Password are specified and Integrated Security is set to true, the User ID and Password will be ignored and Integrated Security will be used.

    0 讨论(0)
提交回复
热议问题