Forum Discussion

w0ns0ng's avatar
w0ns0ng
Microsoft Employee
2 years ago

Connecting to SQL Endpoint from a noteobok using Service Principal?

Anyone had success connecting to SQL endpoint from a notebook using Service Principal? 

 

I get "ActiveDirectoryServicePrincipal" is not valid using JDBC. Tried installing msal4j and mssql conenction jar, but couldnt figure it out.

 

I also tried using ADAL to generate access token instead but not sure what the resource URL would be. Tried various combinations but they all end up with an error (TCP/IP Connection).

 

I did see a blog post about using Pyodbc, but was hoping to use JDBC using Spark SQL as that works without an issue in Data Bricks.

 

Thanks!

5 Replies

    • w0ns0ng's avatar
      w0ns0ng
      Microsoft Employee

      Thanks for your response. I did see the blog post from other threads, too, but I believe it's really about adding service principal to the workspace, not necessarily for SQL Endpoint using Service Principal. The setting is turned on for me regardless, and I am already able to use Data Studio and Dataflow to connect to the SQL endpoint, just that I couldn't find a way to do it using a Notebook and JDBC.

       

      I also saw that there is a way to do it using Pyodbc, but that would require using Pandas then converting to PySpark. I was hoping to use JDBC directly in Spark as that works without an issue in Data Bricks.

       

      Thanks!

      • v-cboorla-msft's avatar
        v-cboorla-msft
        Microsoft Employee

        Hi w0ns0ng 

         

        Thanks for using Microsoft Fabric Community.

        Apologies for the delay in response.

        I found an article which might help you. In this article they are using AAD/Entra username and password, but using other connection string options, I believe you can also use the same method to connect using Service Principle accounts.

         

        I hope this information helps. If you have any further questions please do let us know.

         

        Thanks.