Hi @Pragya Sharma , when upgrading from AppAuthentication to Azure.Identity, you can use the DefaultAzureCredential class to authenticate your application. The DefaultAzureCredential class tries multiple authentication methods in a specific order until it finds a successful authentication method. The order of authentication methods is:
- Environment variables
- Managed Identity
- Visual Studio
- Azure CLI
- Interactive
To use the DefaultAzureCredential class in your Console Application, you can add the following code:
using Azure.Identity;
var credential = new DefaultAzureCredential();
This will create a new instance of the DefaultAzureCredential class, which will try to authenticate using the methods listed above.
Regarding the SQL connection error, it is possible that the service principal you are using does not have the necessary permissions to access the SQL database. You can check the permissions of the service principal by going to the SQL database in the Azure portal and checking the "Access control (IAM)" tab. Make sure that the service principal has the necessary permissions to access the database.
If the service principal has the necessary permissions, you can try using the ClientSecretCredential class to authenticate your application. Here is an example of how to use the ClientSecretCredential class:
using Azure.Identity;
var credential = new ClientSecretCredential(
"<tenant-id>",
"<client-id>",
"<client-secret>"
);
Replace <tenant-id>, <client-id>, and <client-secret> with the appropriate values for your service principal.
Please let me know if you have any questions and I can help you further.
If this answer helps you please mark "Accept Answer" so other users can reference it.
Thank you,
James