Solved

Connect to Azure SQL DB via Active Directory Password

  • 7 September 2023
  • 4 replies
  • 50 views

Badge +1

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

icon

Best answer by ravi.pothana 7 September 2023, 15:47

View original

4 replies

Userlevel 2
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 2
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!

Reply