Microsoft has given documentation on how to connect through managed identity. it's okay for Azure AD user but I want to use User assigned identity which I've created in Azure portal.
var conn = (System.Data.SqlClient.SqlConnection)Database.Connection;
var credential = new Azure.Identity.DefaultAzureCredential();
var token = credential.GetToken(new Azure.Core.TokenRequestContext(new[] { "https://database.windows.net/.default" }));
conn.AccessToken = token.Token;
Code provided by Microsoft for creating connection with default Azure credential.
It was working with system assigned identity. Getting error while making connection for user assigned identity.
When connecting to an SQL server you basically have 2 options:
It looks like what you want to do is:
To do this you must: