Published aspnet website fails to connect to the sql server database using IIS

Lerato_Dev 1 Reputation point
2021-12-08T14:21:47.767+00:00

Published aspnet website fails to connect to the sql server database using IIS, i am using local host.

Windows development Internet Information Services
Developer technologies ASP.NET ASP.NET Core
SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2021-12-08T16:23:53.573+00:00

    there are several possible issues

    1) login failure - app pool account does not have access
    2) invalid connection string - syntax error
    3) firewall rules block access
    4) sqlserver not configured for remote access

    0 comments No comments

  2. Bruce Zhang-MSFT 3,771 Reputation points
    2021-12-09T02:12:22.05+00:00

    Hi @Lerato_Dev ,

    Please show more information about fail connection. Screenshoots, error code and error message.

    In most cases, the connection problems I have encountered are caused by permissions. So please check if the application pool is set to have permission to access the database. You can set permissions according to the following steps.

    • Open cmd with administrator rights. cd C:\Program Files\Microsoft SQL Server\xxx\Tools\Binn. Find sqllocaldb.exe.
    • Execute statements sqllocaldb.exe create xxxx.
    • sqllocaldb.exe share xxxx.
    • sqllocaldb.exe start xxxx.
    • Open this instance, the servername is (LocalDb)\.\xxxx, select security-logins, right click to add a user.
    • Login name is IIS APPPOOL\application pool name, windows authentication, check public and sysadmin in server role, and create a new login name NT AUTHORITY\SYSTEM in the same way.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Bruce Zhang

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.