Connect to azure to read a db

Hello all

i can do this from VS but how to do it in UiPath

using Microsoft.IdentityModel.Clients.ActiveDirectory;

using System.Data.SqlClient;

string TenantID = "TenantID" ;

//The service principle details

string clientId = "ClientID" ;

string clientSecretKey = "SecretKey" ;

string AadInstance = "https://login.windows.net/{0}" ;

string ResourceId = "https://database.windows.net/" ;

AuthenticationContext authenticationContext = new AuthenticationContext( string .Format(AadInstance, TenantID));

ClientCredential clientCredential = new ClientCredential(clientId, clientSecretKey);

AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(ResourceId, clientCredential).Result;

AzureSPNToken = authenticationResult.AccessToken;

string strSQL = "SELECT SERVERPROPERTY('Edition')" ;

string strConn = "Server=tcp:myserver.database.windows.net" ; Initial Catalog=database1; Application Name=SQLAudit;";

SqlConnection SQLconn = new SqlConnection(strConn);

SQLconn.AccessToken = AzureComponents.AzureBuild.GetAzureSPNToken(ServerName);

SqlCommand SQLcmd = new SqlCommand(strSQL, SQLconn);

SQLconn.Open();

SQLcmd.CommandText = strSQL;

string strQueryResult = ( string )SQLcmd.ExecuteScalar();

SQLconn.Close();

Thanks in advance,.

@Hazem_Saleh,

Kindly refer this.

Thanks,
Ashok :slight_smile: