You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何设置Azure SQL Server默认定价层及EF6初始化器创建S0 DTU数据库

Answers to Your Azure SQL & EF6 Questions

Question 1: Can I set a default pricing tier for Azure SQL Databases on an Azure SQL Server?

Short answer: No, there's no built-in setting on the Azure SQL Server itself to define a default pricing tier for new databases. When you create a database via the Azure Portal, CLI, PowerShell, or even automated tools like EF6, you have to explicitly specify the tier (DTU or vCore) unless you use a workaround to enforce it.

That said, you can create a "de facto default" with these approaches:

  • Azure Policy: Build a policy that either enforces all new databases to use your desired tier (like S0 DTU) or blocks creation if the tier isn't specified. This ensures every database under the server adheres to your standard.
  • Automation Scripts/ARM Templates: Use a pre-configured ARM template or PowerShell/CLI script to create databases. Hardcode your preferred pricing tier in the script, so anyone using it automatically gets databases with that tier without manual input.

Question 2: Can I specify a default database type (like S0 DTU) when EF6 creates a database on Azure SQL?

When EF6's database initializers (like CreateDatabaseIfNotExists) spin up a database on Azure SQL, they default to the vCore-based General Purpose tier (GP_Gen5_1)—and there's no way to set the pricing tier directly in the connection string to override this.

Here are your most reliable workarounds to get an S0 DTU database:

  1. Pre-create the empty database manually/scripted:
    Head to the Azure Portal (or use CLI/PowerShell) and create an empty S0 DTU database first. Then point your EF6 connection string to this existing database. The initializer will only build tables and schema instead of creating a new database, so you keep full control over the pricing tier.

  2. Customize the initialization logic:
    Build a custom database initializer that first uses Azure's management APIs (like the Azure.ResourceManager.Sql client library) to create an S0 DTU database, then proceeds with EF's schema setup. Note this requires your app to have Azure management permissions (e.g., via a managed identity), which might not fit all production scenarios.

  3. Use EF Migrations instead of auto-initialization:
    Generate migration scripts locally, create your S0 DTU database in Azure first, then run the migration scripts against it. This gives you complete control over both the database's configuration and schema deployment.


内容的提问来源于stack exchange,提问作者Jon Ryan

火山引擎 最新活动