I'm connecting db with service principal by using below method in express using link
but while running migrations it will establish connection from db.config file where db.config file contains
"development": {
"username": process.env.DB_USER,
"password": process.env.DB_PASSWORD,
"database": process.env.DB_DATABASE,
"host": process.env.DB_HOST,
"dialect": "mssql",
"logging": false
},
so how to configure the db.config file for service principal method
Follow the below steps to configure the
db.configfile for service principal method:Create an
App registrationas shown belowProvide name of the application and click on
Register:Note the
ClientIdandTenantIdafter registeringGenerate the client secret which is present in
Certificates & Secretsand note thesecretId.Grant permissions to the Service Principal which you have created. To grant permission, navigate to the
Access controlwhich is present in the Azure server and go toAdd role assignmentas shown below.Select role which is needed to access the db. I selected
SQL DB Contributorrole.After selecting the role, select the member to which you want to assign the role.
After adding the role assignment, now provide the required config details accordingly in the
db.configBy running your node application it will connect successfully to the db as you can see in the output below.