dna
dna

Reputation: 626

.NET 8 Azure database user managed identity

I have an ASP.NET Core 8 Web API that uses Entity Framework Core. I deploy my application on an Azure Linux service app.

My API connects to an Azure SQL Server database. I used the user managed identity on my app service and I added it in BDD.

My problem is that I do not find how to do in .NET 8 to use the connection managed user identity and what should be the format of the string connection.

Upvotes: 0

Views: 525

Answers (1)

Md Farid Uddin Kiron
Md Farid Uddin Kiron

Reputation: 22523

My problem is that I do not find how to do in .NET 8 to use the connection managed user identity and what should be the format of the string connection.

Based on your scenraio and description, as explained in comment, you should have Authentication parameters followed by your Database name and UserId of your ClientIdOfManagedIdentity

So bsically, we have two ways to handle managed identity:

  1. System-assigned managed identity and
  2. User-assigned managed identity

Your connection string should have following format:

string ConnectionString1 = @"Server=YourServer.database.windows.net; Authentication=Active Directory Managed Identity; Encrypt=True; Database=YourDbName";

using (SqlConnection conn = new SqlConnection(ConnectionString1)) {
    conn.Open();
}

appsettings.json:

"ConnectionStrings": {
  "DefaultConnection": "Server=YourServer.database.windows.net; Authentication=Active Directory Managed Identity; Encrypt=True; Database=YourdatabaseName"
}

Note: Please refer to this official document for more example and format. If you still encounter the issue, then check this document as well.

Upvotes: 0

Related Questions