ステップ 1: Azure ポータルで clientId、Token、および clientSecret を作成する必要があります。このチュートリアルを使用してください(混乱を招くだけのものがたくさんあります)。これは機能します。トークン、clientID、およびクライアント シークレットを取得する方法
ステップ 2 : 次に、残りの API または SDK を使用するかどうかを選択する必要があります。私は SDK を好みますが、それはあなた次第です (SDK を使用しているすべての json 値を把握する必要はありません)。ステップ 3 以降は、SDK を選択したことを前提としています。
SDK の前提条件をインストールするには、次の nuget パッケージが必要です。
Install-Package Microsoft.Azure.Management.Fluent
Install-Package Microsoft.Azure.Management.ResourceManager.Fluent
また、SQL には次のものが必要です。
Microsoft.Azure.Management.Sql.Fluent
認証するには、ステップ 1 のトークンが必要です。
ステップ 3:次に、SDK の使用方法に関するこの例を見てください。適用方法がわかります。
Azure SQL SDK
最後に:上記のすべてが完了したら、コードスニペットを次に示します-見事に仕事をします.
string tenantId = "9596ecae-xxxxxxx";
string clientAppId= "51c28b54-xxxxxxxxx";
string secret = "@w6.Quv--your secret";
credentials = SdkContext.AzureCredentialsFactory
.FromServicePrincipal(clientAppId,
secret,
tenantId,
AzureEnvironment.AzureGlobalCloud);
var azure = Microsoft.Azure.Management.Fluent.Azure
.Configure()
.Authenticate(credentials)
.WithDefaultSubscription();
var database = azure.SqlServers
.GetById("/subscriptions/<your specific>/resourceGroups/<your specific>/providers/Microsoft.Sql/servers/<your specific>")
.Databases.GetById("/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Sql/servers/xxx/databases/xxx");
var result = database.Update()
.WithEdition(DatabaseEditions.Standard)
.WithServiceObjective(ServiceObjectiveName.S0) <-- CHANGE LEVEL OF DB.
.Apply();
SQL および DB 文字列名のヒントとヘルパー:上記のコードを置き換える正しい文字列を取得するのは難しいです。ショートカットは、最初に List を呼び出すことです。次にデバッグして GetById 関数に何を配置するかを確認し、最初にこれを呼び出して結果を確認します。
azure.SqlServers.List() <-- Debug this and you will see the full names of the Database Servers string names
Then do azure.SqlServer.Databases.List() <-- an array of objects where you can get the string for the database name.
お役に立てば幸いです - ドキュメントはひどいものです。