# Azure SQL Server with Azure Active Directory Authentication

**URL:** <https://forum.inductiveautomation.com/t/azure-sql-server-with-azure-active-directory-authentication/49978>\
**Category:** Ignition\
**Tags:** ignition81, database\
**Created:** [August 16, 2021, 7:49pm UTC](https://forum.inductiveautomation.com/t/azure-sql-server-with-azure-active-directory-authentication/49978 "2021-08-16T19:49:22Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 11, 2024, 6:30pm UTC](https://forum.inductiveautomation.com/t/azure-sql-server-with-azure-active-directory-authentication/49978/21 "2024-04-11T18:30:06Z")

</div>

> [@SBL\_MC](#):
>
> Can this still be JAR related, or do I need look at the connection props?

It's probably still JAR related. Full stack trace to go along with the error would be useful.

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [April 11, 2024, 7:40pm UTC](https://forum.inductiveautomation.com/t/azure-sql-server-with-azure-active-directory-authentication/49978/22 "2024-04-11T19:40:33Z")

</div>

Wrapper.log and Diagnostic logs seem to not show any relevant.

The two artifacts you listed in your pom.xml suggestion I can find in /home/admintest/.m2/repository/com/microsoft/azure, these JAR files has been moved to the ignition folde.r

---

<div class="post-metadata">

**Author:** ![AndrewWilliams](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@AndrewWilliams](https://forum.inductiveautomation.com/u/AndrewWilliams)\
**Post date:** [August 9, 2024, 7:33pm UTC](https://forum.inductiveautomation.com/t/azure-sql-server-with-azure-active-directory-authentication/49978/23 "2024-08-09T19:33:48Z")

</div>

I was recently trying to connect to an Azure SQL Server using the `ActiveDirectoryServicePrincipal` method, and this thread helped point me in the right direction, but for completeness I thought I would explain how I got it to work.

1. Get `msal4j` and all dependencies with Maven

- I used WSL for all of this which seemed easier than trying to do it on Windows directly
- Install jdk, I'm using `openjdk 11`
- Download and unpack Maven, add to path

```python
wget https://dlcdn.apache.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz
tar xzvf apache-maven-3.9.8-bin.tar.gz
mv apache-maven-3.9.8 /opt/
# Add mvn to path, I did this in my .zshrc
export PATH=$PATH:/opt/apache-maven-3.9.8/bin

```

- See [Maven – Installing Apache Maven](https://maven.apache.org/install.html) for latest version/instructions
- As @Kevin.Herron mentioned, create a temp folder with a `pom.xml` file based on his post - I changed the version to the latest `1.16.2`
- Run `mvn install dependency:copy-dependencies` in the temp folder with the `pom.xml` file
- This will create a new folder `target`, all of the required `.jar` files will be in `target > dependency`

1. Copy all of the dependencies to `{IGNITION_PATH}/lib/core/gateway`
2. You also need to put the `mssql-jdbc-auth-xxx.dll` in the `{IGNITION_PATH}/lib` folder, you can get that directly from MSFT: [Release notes - JDBC Driver for SQL Server | Microsoft Learn](https://learn.microsoft.com/en-us/sql/connect/jdbc/release-notes-for-the-jdbc-driver?view=sql-server-ver16#previous-releases)
  - Note I'm using the stock driver, `9.4.0`

3. Restart your gateway
4. If you are using the stock `9.4.0` driver, you will need to add some properties to the **Extra Connection Properties** section, here's how mine looks

```python
databaseName={db_name};authentication=ActiveDirectoryServicePrincipal;AADSecurePrincipalId={clientId};AADSecurePrincipalSecret={clientSecret};

```

- You can leave the username and password blank
- If you are using a newer jdbc driver, you will need to put the `clientId` in the `Username` field, and the `clientSecret` in the `Password` field, and DO NOT add the `AADSecurePrincipalId` or `AADSecurePrincipalSecret` properties, otherwise it won't connect.
- MSFT docs: [Connect using Microsoft Entra authentication - JDBC Driver for SQL Server | Microsoft Learn](https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver16#connect-using-activedirectoryserviceprincipal-authentication-mode:~:text=Set%20the%20principal%20ID%20and%20principal%20secret%20using%20setUser%20and%20setPassword%20in%20version%2010.2%20and%20up%2C%20and%20setAADSecurePrincipalId%20and%20setAADSecurePrincipalSecret%20in%20version%209.4%20and%20below).

Hope this helps someone out!

[Previous page](https://forum.inductiveautomation.com/t/azure-sql-server-with-azure-active-directory-authentication/49978.md?page=1)
