From .NET Core app, call Azure Rest API to delete Azure SQL Db

177 views Asked by At

Question: In my WPF Core app, how can I call the following Azure REST API to delete a Azure SQL Db in my Azure subscription:

DELETE https://management.azure.com/subscriptions/mySubscriptionID/resourceGroups/myResourceGroup/providers/Microsoft.Sql/servers/myAzureSQLServer/databases/myAzureSQLDb?api-version=2019-06-01-preview

I am used to working on Microsoft Graph that has a RESTful web API that enables you to access Microsoft Cloud service resources. Microsoft has Graph SDKs that are designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph. The SDKs include two components: a service library and a core library. For example, the following C# code would get the events from Outlook. But I am not sure if something similar exists in Azure SQL Database Rest API:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

    var events = await graphClient.Me.Events
        .Request()
        .Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")
        .Select("subject,body,bodyPreview,organizer,attendees,start,end,location")
        .GetAsync();
1

There are 1 answers

0
Derviş Kayımbaşıoğlu On

Are you looking for something like this?

var subscriptionId = "";
var resourceGroupName = "";
var serverName = "";
var databaseName = "";

using var handler = new HttpClientHandler();
using var client = new HttpClient(handler); 

var requestString = $"DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}?api-version=2019-06-01-preview"
var response = await client.DeleteAsync(requestString);