CopyPastor

Detecting plagiarism made easy.

Score: 0.8287246385058626; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2023-10-17
by Bhavani

Original Post

Original - Posted on 2023-06-29
by Bhavani



            
Present in both answers; Present only in the new answer; Present only in the old answer;


To connect an Azure SQL Server from an Azure asp.net Web API with managed identity authentication, provide the connection string in the following format in Appsettings.json:
```csharp "ConnectionStrings": { "QuotesDatabase": "Server=tcp:<servername>.database.windows.net,1433; Database=<databasename>;" } ```
Use the code below for the connection:
```csharp var connectionString = Configuration.GetConnectionString("<connectionstringname>"); services.AddTransient(a =>{ var sqlConnection = new SqlConnection(connectionString); var credential = new DefaultAzureCredential(); var token = credential .GetToken(new Azure.Core.TokenRequestContext( new[] { "https://database.windows.net/.default" })); sqlConnection.AccessToken = token.Token; return sqlConnection; ```
![enter image description here](https://i.imgur.com/W6tWLBF.png)
Set admin as desired on the SQL Server:
![enter image description here](https://i.imgur.com/hguf8xo.png)
Choose an administrator account for Azure service authentication to retrieve the token credentials.
Image for reference:
![enter image description here](https://i.imgur.com/NkMlmEE.png)
Enable the system-assigned managed identity in the "on" state of the Azure app service.
![enter image description here](https://i.imgur.com/OXQ6gXY.png)
Log in to the SQL Server with an administrator account, add a user to the database, and assign a role to the user:
```csharp create user [<appName>] from external provider; alter role db_datareader add member [<appName>]; alter role db_datawriter add member [<appName>]; ```
![enter image description here](https://i.imgur.com/VTc4Jxj.png)
The database successfully connects to the app.
Image for reference:
![enter image description here](https://i.imgur.com/Fjip7AY.png)
To connect Azure sql database from web API through system assigned managed identity authentication mention the connection string in below format in Appsetting.json:
"ConnectionStrings": { "QuotesDatabase": "Server=tcp:<servename>.database.windows.net,1433; Database=<databasename>;" }
Use below code for connection.
var connectionString = Configuration.GetConnectionString("<connectionstringname>"); services.AddTransient(a =>{ var sqlConnection = new SqlConnection(connectionString); var credential = new DefaultAzureCredential(); var token = credential .GetToken(new Azure.Core.TokenRequestContext( new[] { "https://database.windows.net/.default" })); sqlConnection.AccessToken = token.Token; return sqlConnection;
![enter image description here](https://i.imgur.com/W6tWLBF.png)
set admin for sql server as you want.

![enter image description here](https://i.imgur.com/hguf8xo.png)
choose administrator account for azure service authentication to retrieve the token credentials.
Image for reference:
![enter image description here](https://i.imgur.com/NkMlmEE.png)
Enable system assigned manage identity in on state of Azure app service.
![enter image description here](https://i.imgur.com/OXQ6gXY.png)
Login to sql server with administrator add user to the database and assign role to the user

create user [<appName>] from external provider; alter role db_datareader add member [<appName>]; alter role db_datawriter add member [<appName>];

![enter image description here](https://i.imgur.com/VTc4Jxj.png)
The database successfully connected to the app.
Image for reference:
![enter image description here](https://i.imgur.com/Fjip7AY.png)


        
Present in both answers; Present only in the new answer; Present only in the old answer;