Application logon failure in IIS when trying to connect with SQLServer

4

When I run an application of type site in visual studio, the connections to the database work normally. But when trying to run IIS 7 to perform some tests, I get the following message:

  

Unable to open the "XXX" database requested by logon. Logon failed.

     

User login failed 'IIS APPPOOL \ DotNet4'.

The specific Bank with which I am having difficulty connecting, left the authentication method configured to be accessed through the Windows user login.

The conectionString of my Web.config looks like this:

<add name="LocalConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=XXX;Connect Timeout=3000; Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

Note : I was told that I should go into the application pool and set the Identity option to that of my user, my user has a password and is not accepting me to add it in this dialog:

Insertuserin"Identity" in IIS

    
asked by anonymous 30.06.2017 / 14:41

3 answers

5

This does not have to do with IIS configuration itself. The error says that the IIS APPPOOL \ DotNet4 server can not connect to SQL Server.

This is because your ASP.NET application is using Integrated Security , this means that the application will use the user configured in the pool > to which it belongs to connect to SQL Server.

Most likely, when you installed SQL Server you defined that only the current user would have access to the database.

Therefore, you need to add the IIS APPPOOL \ DotNet4 user as a SQL Server login .

  • Open SSMS and expand the security node

  • Right-click logins and then new login

  • At Login Name enter the user name that appears in the error.

    Note: I've seen a lot of people say that you should not click search , because some error occurs. So, just in case, just paste the user name into the text field.

  • AnotheroptionistochangetheconnectionformforaSQLServeruser.Ifyouhavesetupauserintheinstallation,youcanonlyuseitbychangingyourconnectionstringto

    <addname="LocalConnection" 
         connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=XXX;
         Connect Timeout=3000; User ID=XXXX; Password=XXXX;
         MultipleActiveResultSets=True" 
         providerName="System.Data.SqlClient" />
    

    If there is no registered user or if you do not remember the password set up in the installation, just open the same screen as the steps above, choose SQL Server Authentication and enter the credentials .

        
    30.06.2017 / 14:56
    3

    IIS runs a user of your own and is not authorized to login to your server. Probably the user who is authorized is your windows user and not the IIS user.

    To resolve this you can create a SQL Server user to connect to the database and change your connection string to connect to it. Your connection string looks like this:

    <add name="LocalConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=XXX;Connect Timeout=3000; User ID=USUARIO;Password=SENHA;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    

    Or authorize the IIS user to connect to your bank

        
    30.06.2017 / 14:59
    -4

    link

    Run this in sql

    SQL

    IF NOT EXISTS (SELECT name FROM sys.server_principals WHERE name = 'IIS APPPOOL \ DefaultAppPool')

    BEGIN

    CREATE LOGIN [IIS APPPOOL\DefaultAppPool] 
      FROM WINDOWS WITH DEFAULT_DATABASE=[master], 
      DEFAULT_LANGUAGE=[us_english]
    

    END GO

    CREATE USER [ContosoUniversityUser]   FOR LOGIN [IIS APPPOOL \ DefaultAppPool] GO

    EXEC sp_addrolemember 'db_owner', 'ContosoUniversityUser' GO

        
    09.01.2019 / 04:14