I want to Access the Azure SQL Database using App service API(Java) with MSI (Managed Service Identity) authentication.
I am trying to find out the how to connect Azure sql with MSI from Azure App service for Java.
Here is the connection string I am using.
jdbc:sqlserver://mysqldb.database.windows.net:1433;database=TestDB;Authentication=ActiveDirectoryMsi;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
Here is the steps I used:
- Create AAD group
- Add Azure web app'S MI(Managed Identity) to this AAD group
- Add this group as Active Directory admin to Azure SQL Server
Create user and give roles for this group.
CREATE USER [myAADgroup] FROM EXTERNAL PROVIDER; ALTER ROLE db_datareader ADD MEMBER [myAADgroup]; ALTER ROLE db_datawriter ADD MEMBER [myAADgroup]; ALTER ROLE db_ddladmin ADD MEMBER [myAADgroup];
Connection string for JDBC driver.