0

Currently, I create databases and attach them to an SQL elastic pool:

database = await sqlServer.Databases.Define(mainDb.DbName).WithExistingElasticPool(pool.Name).CreateAsync();

Instead, I want to create databases with tier "General Purpose: Serverless, Gen5, 1 vCore", but I couldn't find any method that offers that possibility.

This feature is still in preview, I can't find anything on the forums on this. How can I achieve this?

2
  • I know how to create a Serverless with PowerShell. Do you want me to provide that as possible answer with an example? Commented Aug 12, 2019 at 23:03
  • @AlbertoMorillo For powershell it's in the official docs : learn.microsoft.com/en-us/azure/sql-database/… , but I'm looking for the c# sdk way to do it. Commented Aug 12, 2019 at 23:12

3 Answers 3

2

As an addendum to @Jim Xu accepted answer, the API has changed.

var database = sqlserver.Databases.Define("test").WithEdition("GeneralPurpose").WithServiceObjective("GP_S_Gen5_1").Create();

The WithEdition is now a DatabaseEdition edition type, and WithServiceObjective is now a ServiceObjectiveName. Both of these are muddled string enums with lists of version types. They do both also accept a .Parse() method. So the line should now be:

var database = sqlserver.Databases.Define("test")
             .WithEdition(**Database.Edition.Parse("GeneralPurpose")**)
             .WithServiceObjective(**ServiceObjectiveName.Parse("GP_S_Gen5_1")**)
             .Create();
Sign up to request clarification or add additional context in comments.

Comments

1

According to my test, we can use the following c# code to create "General Purpose: Serverless, Gen5, 1 vCore" database

var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(client,key,tenant,AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Configure().Authenticate(credentials).WithSubscription(SubscriptionId);
var sqlserver=azure.SqlServers.GetById("/subscriptions/<your subscrption id>/resourceGroups/<your resource group name>/providers/Microsoft.Sql/servers/<your server name>");
var database = sqlserver.Databases.Define("test").WithEdition("GeneralPurpose").WithServiceObjective("GP_S_Gen5_1").Create();
Console.WriteLine(database.ServiceLevelObjective);
Console.WriteLine(database.Edition);
Console.WriteLine(database.Name);
Console.ReadLine();

enter image description here

Comments

0

Please reference this tutorial: Create a new elastic database pool with C#.

It provides the code example about Create a new database in a pool:

Create a DataBaseCreateorUpdateProperties instance, and set the properties of the new database. Then call the CreateOrUpdate method with the resource group, server name, and new database name.

// Create a database: configure create or update parameters and properties explicitly
DatabaseCreateOrUpdateParameters newPooledDatabaseParameters = new DatabaseCreateOrUpdateParameters()
{
    Location = currentServer.Location,
    Properties = new DatabaseCreateOrUpdateProperties()
    {
        Edition = "Standard",
        RequestedServiceObjectiveName = "ElasticPool",
        ElasticPoolName = "ElasticPool1",
        MaxSizeBytes = 268435456000, // 250 GB,
        Collation = "SQL_Latin1_General_CP1_CI_AS"
    }
};

var poolDbResponse = sqlClient.Databases.CreateOrUpdate("resourcegroup-name", "server-name", "Database2", newPooledDatabaseParameters);

Please try to replace "standard" with the price tier "General Purpose: Serverless, Gen5, 1 vCore".

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.