System.Data.SqlClient.SqlException: Login failed for user

前端 未结 10 2337
难免孤独
难免孤独 2020-12-01 14:11

Working with my project in debug I have no issues. However running it in IIS I am getting this error:

System.Data.SqlClient.SqlException: Login failed for us

相关标签:
10条回答
  • 2020-12-01 14:20

    You can also get this error if your SQL Server has not been configured to use Mixed mode authentication - it doesn't actually tell you that this is not enabled!

    0 讨论(0)
  • 2020-12-01 14:22

    I had similar experience and it took me time to solve the problem. Though, my own case was ASP.Net MVC Core and Core framework. Setting Trusted_Connection=False; solved my problem.

    Inside appsettings.json file

    "ConnectionStrings": {
        "DefaultConnection": "Server=servername; Database=databasename; User Id=userid; Password=password; Trusted_Connection=False; MultipleActiveResultSets=true",
      },
    
    0 讨论(0)
  • 2020-12-01 14:27

    Assuming you're intending to use Windows Authentication to impersonate the service account, you have to set up Windows Authentication in both IIS and ASP.NET.

    In IIS, make sure that the Windows Authentication module is added and enabled. Also make sure your application pool is running under a domain account, not a local account.

    In ASP.NET make sure the authentication mode attribute is set to "Windows"

    <system.web>
        <authentication mode="Windows"/>
     </system.web>
    
    0 讨论(0)
  • 2020-12-01 14:28

    I faced the same situation. Create your connection string as follows.

    Replace

    "connectionString": "Data Source=server name;Initial Catalog=DB name;User id=user id;Password=password;Integrated Security=True;MultipleActiveResultSets=True"
    

    by

    "connectionString": "Server=server name; Database=Treat; User Id=user id; Password=password; Trusted_Connection=False; MultipleActiveResultSets=true"
    
    0 讨论(0)
  • 2020-12-01 14:35

    I just ran into this error and it took days to resolve. We were thrown for a loop by the red-herring error message mentioned in the initial question, plus the Windows Event Viewer error log indicated something similar:

    Login failed for user '(domain\name-PC)$'. Reason: Could not find a login matching the name provided. [CLIENT: <local machine>]
    

    Neither of these was true, the user had all the necessary permissions in SQL Server.

    In our case, the solution was to switch the Application Pool Identity in IIS to NetworkService.

    0 讨论(0)
  • 2020-12-01 14:40

    Just set Integrated Security=False and it will work ,according to a comment difference between True and False is:

    True ignores User ID and Password if provided and uses those of the running process, SSPI(Security Support Provider Interface ) it will use them if provided which is why MS prefers this. They are equivalent in that they use the same security mechanism to authenticate but that is it.

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