Search code examples
sql-serverazureazure-hybrid-connections

Connecting to On-Premises SQL Server from API in Azure App Service


I am trying to connect to an on-premises SQL Server from my API which i have deployed to Azure App Service. I have established a Azure Hybrid Connection to connect between on-premises SQL and Azure. I created a connection string which included username and password as that of a local login i created in the On-Premises server. This is allowing me to connect.

Connection String:

Data Source=;Initial Catalog=;User=;Password=;MultipleActiveResultSets=True

However i want to connect to the server using windows authentication. My System account has access on the server, but when using connection string as -

Data Source=;Initial Catalog=;Integrated Security=SSPI;User=;Password=;

Or

Data Source=;Initial Catalog=;Integrated Security=SSPI;

It is giving error as

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

Please suggest how to use windows mode of authentication while forming connection string to the on-premises SQL Server from Azure App Service.


Solution

  • Azure Hybrid Connection does not appear to support Active Directory and hence Windows Authentication will not work. See note about sql auth being required in Official MS documentation.

    https://learn.microsoft.com/en-us/azure/biztalk-services/integration-hybrid-connection-overview

    Also, look at the following SO question where one of the answers details common issues faced this setup:

    C# web app not connecting to on premise SQL Server through Azure hybrid Connection

    You are unlikely to get around this, especially if you are hosting your app as a web app.