The error “Login failed for user 'NT AUTHORITY\IUSR'” in ASP.NET and SQL Server 2008

前端 未结 8 811
孤街浪徒
孤街浪徒 2020-12-06 16:11

My ASP.NET v3.5 web application is throwing the following exception when it attempts to open a connection to a SQL Server 2008 database:

System.Data.SqlC

相关标签:
8条回答
  • 2020-12-06 17:01

    This problem is shown when you restore a new database on your last database.

    To resolve this you must go to sqlserver, then security and then set your apppool again.

    0 讨论(0)
  • 2020-12-06 17:03

    I had had the same problem and solved this by changing application pool.

    0 讨论(0)
  • 2020-12-06 17:05

    Instead of using Integrated Security=True; in connection string, just use username and password authentication user=sa; pwd=mypassword;

    0 讨论(0)
  • 2020-12-06 17:07

    In case it helps someone, in web.config I added <identity impersonate="false" /> for this error to go away (under <system.web>)

    0 讨论(0)
  • 2020-12-06 17:11

    I would suggest to create a separate (preferably domain) account and specify it in the connection string (usually in web.config) Then you can limit permissions on the web server what this account can and cannot do. Then you can grant this account required permissions in SQL server.

    0 讨论(0)
  • 2020-12-06 17:13

    It's important to note that you'll get this error, as I just did, if you don't have IIS configured to allow impersonation, but, you have your web.config attempting to do impersonation.

    I just came across this exact error, and all of the following steps are required (but I was missing the first step:

    1.) Ensure ASP.NET impersonation is enabled on your IIS web server:

    2.) Combine that with configuring your site to use impersonation (web.config):

       <system.web>
         <identity impersonate="true" userName="your_service_acct" password="***" />
    

    3.) The above steps presume that you have a SQL Login setup on your MSSQL for 'your_service_acct' with permissions

    When running on localhost, against a localdb, or even a remote db that you personally have permissions on, the development IIS runs as if it were YOU - and everything just magically works. So, in debug mode, you don't need to create a special web.config..

    As soon as you deploy your site onto some kind of server (in my case, our TEST environment) you'll likely need to have done the above steps I just detailed, because IIS will try to connect as the application pool user, which is not usually what you want administratively speaking. So, that's when you want to start using web.config transformations, so Visual Studio will insert the appropriate identity impersonate="true" during your 'Publish...' deployment step.

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