Hello Sreenidhi Palimar
Thank you so much for your response.
I am glad that your issue is resolved after switching to SSMS.
Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I had posted your solution.
Please click "Accept" the answer as original posters help the community find answers faster by identifying the correct answer.
Issue: Unable to access SQL managed instance.
Resolution: You are able to connect now after switched to Microsoft SSMS and choose authentication method as Azure Active Directory - Universal with MFA.
Just for your future reference and to know about the java application,
We would like to inform you that, this issue typically arises when the MSAL4J library is either missing from the runtime class path or fails to initialize correctly for Active Directory authentication, even if the SQL Server JDBC driver is correctly provided at runtime.
All the underlying database drivers such as the SqlClient, JDBC, OLEDB, ODBC have progressively been dropping ADAL as a dependency and started migrating to MSAL. Such is the case of JDBC which has removed ADAL4J as a dependency and added MSAL4J as the replacement.
The JDBC driver is an open source project which can be found here microsoft/mssql-jdbc: The Microsoft JDBC Driver for SQL Server is a Type 4 JDBC driver that provides database connectivity with SQL Server through the standard JDBC application program interfaces (APIs). (github.com)
Here you can see the release notes Releases · microsoft/mssql-jdbc (github.com)
If you encounter problems with the driver you can file issues directly with the team that manages the project and also scan issues that the community is providing feedback. Issues · microsoft/mssql-jdbc (github.com)
On the SQL Server blog on Tech Community one of the contributors of the project often blogs about the new releases/features SQL Server Blog - Microsoft Community Hub Example of the last article published Hotfix: JDBC Driver 12.4.1 for SQL Server Released - Microsoft Community Hub
Please also check out our tutorials to get started with developing apps in your programming language of choice and SQL Server. SQL Developer Tools | Microsoft
https://github.com/microsoft/mssql-jdbc/issues/1832
This page displays the Library dependencies, as well as the supported authentication options. Our recommendation would be to use the latest version of the JDBC driver for your newer applications.
Ensure MSAL4J is correctly loaded and compatible with your runtime setup using below mentioned troubleshooting steps:
- Confirm Dependency Scope and Version: Ensure that the MSAL4J dependency is included with the appropriate scope and verify that the MSAL4J version is compatible with the SQL Server JDBC driver version you are using.
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.11.0</version> <!-- Use the latest stable version -->
- Verify Dependency Inclusion at Runtime: Since you are adding the SQL Server driver at runtime, ensure that the MSAL4J library is also explicitly included in the classpath at runtime. Double-check any classpath configurations or packaging steps to confirm MSAL4J is available when the application launches.
- Test Loading MSAL4J Before Authentication: Write a simple test in your application to load a class from MSAL4J (Ex: PublicClientApplication.class) before initiating the SQL Server connection. This ensures that MSAL4J is indeed available in the runtime environment. If you encounter a ClassNotFoundException, it indicates MSAL4J isn't on the runtime classpath.
- Include Dependencies in JAR/Package: If you are packaging the application into a JAR, confirm that MSAL4J and its transitive dependencies are included in the packaged JAR. Use the mvn dependency:tree command to confirm that there are no missing dependencies or version conflicts.
- Use Classpath Dependency Injection (as a Test): As a temporary measure, try adding the MSAL4J dependency directly to the runtime classpath to see if the issue resolves. For example, when starting the application, specify the path to MSAL4J like so,
java -cp "path/to/msal4j.jar:path/to/sqljdbc42.jar:path/to/your-app.jar" com.your.MainApp
- Review Logging (Optional): Set up detailed logging in your application to capture class loading or dependency resolution issues related to MSAL4J. This can help pinpoint where the load failure occurs. After confirming MSAL4J is on the runtime classpath and the steps above, try re-running the connection setup with Active Directory authentication.
I hope the information is helpful. Your feedback is important so please take a moment to accept answers. If you still have questions, please let us know what is needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!