title: Getting adal4j/AuthenticationException while connecting to Azure SQL from Google Dataproc Cluster
body: <p>Please hear me out.</p>
  <p>I am able to successfully write to Azure SQL server table using <a href="https://docs.microsoft.com/en-us/sql/connect/spark/connector?view=sql-server-ver16" rel="nofollow noreferrer">Apache Spark connector</a> in Dataproc cluster. But then while testing I found sometime that the SQL server database in not available and because of this the write operation fails.</p>
  <p>So, I decided to add an exception logic to check if the database is available or not using the following code before writing to Azure DB,</p>
  <pre><code>    var connection: Connection = null
      val url = &quot;jdbc:sqlserver://***.database.windows.net:1433;databaseName=some_db;encrypt=true;trustServerCertificate=true;authentication=ActiveDirectoryPassword&quot;
      val user = &quot;xxxx&quot;
      val password = ******
      try
            {
              Class.forName(&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;)
              connection = DriverManager.getConnection(url, user, password)
              log.info(s&quot;Successfully established connection on attempt: &quot;+attempts)
              return
            }
  </code></pre>
  <p><strong>This code works fine in my local machine. But while running the same in Dataproc I am getting the below error,</strong></p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: com/microsoft/aad/adal4j/AuthenticationException
  </code></pre>
  <p>I already went though this similar <a href="https://stackoverflow.com/questions/70289697/noclassdeffounderror-com-microsoft-aad-adal4j-authenticationexception-while-conn">issue</a> discussed in SO. But it's bit different for me as the  Apache Spark connector to write to SQL server is working fine. I just want to have the code <code>DriverManager.getConnection(url, user, password)</code> work to test the connection before my write.</p>