Skip to main content
Solved

Connect to Azure SQL DB via Active Directory Password

  • 7 September 2023
  • 5 replies
  • 434 views

Hello,

 

I am trying to connect to an Azure SQL DB with the following connections string:

jdbc:sqlserver:{{server}};database={{db}};user={{username}};password={{password}};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;authentication=ActiveDirectoryPassword

The issue is that when I run the code, I get the following error:

Exception occurred in command execution. 'Could not Connect to Database. Failed to load MSAL4J Java library for performing ActiveDirectoryPassword authentication.'

 

Do you know what is to be done? I have searched and found nothing about this.

 

Thank you

5 replies

Userlevel 3
Badge +8

Hi @ovdptr,

It seems the the bot runner machine is missing required java library to connect to Azure SQL Database, Before you connect to a SQL Server database, JDBC driver must be installed on the bot agent.

 


Download the JDBC Driver: https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=azuresqldb-current

When you download the driver, there are multiple JAR files. The name of the JAR file indicates the version of Java that it supports

Using the JDBC driver: https://learn.microsoft.com/en-us/sql/connect/jdbc/using-the-jdbc-driver?view=azuresqldb-current

 

Hope this helps!

 

Thank you. 

 

Badge +1

I have downloaded and set the Classpath as mentioned in the links, yet I receive the same error.

Is there anything that I am missing?

Thank you!

Userlevel 3
Badge +8

“ActiveDirectoryPassword” authentication mode have more requirements, ensure you have required dependent libraries from the Client setup requirements.

https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver16#client-setup-requirements

 

 

Badge +1

I have managed to get through there.

The only issue is that I do not now how to add the MSAL4J part to the BotAgent.

As the JDBC drivers are ok, since the connection to azure with SQL Server conn type worked previously.

Thank you!

Badge

Running into this issue as well and not understanding where within AA these changes can be made beyond loading the proper DLL which I’ve made certain is in place. 

Reply