How to program to create an Azure Sql database of type Basic / Standard using Entity Framework code

I am using EF 6. My existing code is:

public void CreateOrUpdateCompanyDb(string companyDbName) { try { string connectionString = _connectionStringProvider.GetConnectionString(companyDbName); DbMigrationsConfiguration cfg = CreateMigrationsConfig(connectionString); cfg.AutomaticMigrationsEnabled = false; cfg.AutomaticMigrationDataLossAllowed = false; DbMigrator dbMigrator = new DbMigrator(cfg); dbMigrator.Update(); } catch (MigrationsException exception) { _logger.Error(string.Format("Error creating company database '{0}'",companyDbName), exception); } } 

with the connection string as follows:

 Server=tcp:xxx.database.windows.net,1433;Database=companyDbName;User ID=xxx@xxx ;Password=xxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" 

which creates a database for a particular company. But the problem is that the created database is from a now retired web edition, but I want to create a Basic / Standard / Premium edition.

How should I manipulate the connection string so that the database edition is desired?

+3
source share
1 answer

The release of the Azure Sql database is what you can specify in Create Database . AFAIK, you cannot specify it using the connection string.

The syntax is

 CREATE DATABASE database_name [ COLLATE collation_name ] { (<edition_options> [, ...n]) } <edition_options> ::= { MAXSIZE = { 100 MB | 500 MB | 1 | 5 | 10 | 20 | 30150500 } GB | EDITION = { 'web' | 'business' | 'basic' | 'standard' | 'premium' } | SERVICE_OBJECTIVE = { 'shared' | 'basic' | 'S0' | 'S1' | 'S2' | 'P1' | 'P2' | 'P3' } } [;] 

Given that for your scenario you come up with two options -

  • Before using DbMigrator , explicitly write the code that creates the database if it does not exist using traditional ADO.Net .

  • Another option that comes to mind, but I don’t know enough, and you can delve into it if you want, is to somehow find a way to connect to EF so that you can configure the Create Database that it should generate.

+8
source

Source: https://habr.com/ru/post/1206595/


All Articles