Thank you reaching out to Microsoft Q&A.
Login failed for user '<token-identified principal>'.
This means your Logic App’s Managed Identity is trying to authenticate to Azure SQL Database, but Azure SQL doesn’t recognize or trust it yet. It’s trying to connect with a valid identity token, but if the identity not been created as a SQL user in your database, it leads to 401 unauthorized error.
- Clear cache and try creating the new connection again.
Follow below steps to create an API connection to SQL using system assigned managed identity
- Enable managed identity in logic app and the execute below query in your SQL database.
CREATE USER [System Assigned Managed Identity Name (Your logic app Name)] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [System assigned managed Identity Name]
ALTER ROLE db_datawriter ADD MEMBER [System assigned managed Identity Name]
Navigate to SQL Server -> Access Control (IAM) -> Role assignment, grant SQL Server Contributor role to Managed Identity of your logic app.
Create a connection to Azure SQL server through Logic app Designer. Enable Public access for selected networks.
- Add the SQL Action
Click **+ =>**Search for **"SQL Server"=>**Choose "Execute a SQL query (V2)" =>Create or Select Connection
- A connection form will pop up=> Enter the server's name
servername.database.windows.netand Database name by selecting Enter custom value. - Run the Http Post URL using curl or Postman to execute the query (add parameters if needed).
Run History: Output:
Hope it helps!
Please do not forget to click "Accept the answer” and Yes, this can be beneficial to other community members.
If you have any other questions, let me know in the "comments" and I would be happy to help you.