@Kaustubh Patil sorry for the delay. I have provided Reader permissions to the service principal on the subscription.
Thanks
Saurabh
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to get a list of SQL servers and SQL databases using the SqlManagementClient
from .NET SDK. I have the following requirement:
In order to do so, we are authenticating using service principal. Following is the snippet of the function that we are using to achieve this.
var azureCredentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
Constants.ApplicationId,
Constants.ClientSecret,
Constants.TenantId,
AzureEnvironment.AzureGlobalCloud)
.WithDefaultSubscription(Constants.SubscriptionId);
RestClient restClient = RestClient.Configure()
.WithEnvironment(AzureEnvironment.AzureGlobalCloud)
.WithCredentials(azureCredentials)
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Build();
SqlManagementClient sqlManagementClient = new SqlManagementClient(restClient);
sqlManagementClient.SubscriptionId = Constants.SubscriptionId;
var response = await SubscriptionUsagesOperationsExtensions.ListByLocationAsync(sqlManagementClient.SubscriptionUsages, Constants.Location);
Now the problem part. There are a number of SQL servers that are active under the subscription. Although the above returns an empty list. However if we use a bearer token and list the servers using the same REST API that the above method uses it returns valid results and accurate ones as well. It would be really helpful if you could point out what the issue is with regards to the above example.
@Kaustubh Patil sorry for the delay. I have provided Reader permissions to the service principal on the subscription.
Thanks
Saurabh
As you can see from the discussion above the solution was to set the Reader
permission on the subscription for the client being used to fetch the information. Once the permission is set the solution works just fine.