azure-resource-manager-sql-dotnet
द्वारा microsoft
Azure संसाधन प्रबंधक के माध्यम से Azure SQL संसाधनों की प्रावधान और प्रबंधन के लिए प्रबंधन प्लेन SDK।
npx skills add https://github.com/microsoft/skills --skill azure-resource-manager-sql-dotnetAzure.ResourceManager.Sql (.NET)
Management plane SDK for provisioning and managing Azure SQL resources via Azure Resource Manager.
⚠️ Management vs Data Plane
- This SDK (Azure.ResourceManager.Sql): Create servers, databases, elastic pools, configure firewall rules, manage failover groups
- Data Plane SDK (Microsoft.Data.SqlClient): Execute queries, stored procedures, manage connections
Installation
dotnet add package Azure.ResourceManager.Sql
dotnet add package Azure.Identity
Current Versions: Stable v1.3.0, Preview v1.4.0-beta.3
Environment Variables
AZURE_SUBSCRIPTION_ID=<your-subscription-id> # Required: Azure subscription ID
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
AZURE_TENANT_ID=<tenant-id> # For service principal auth (optional)
AZURE_CLIENT_ID=<client-id> # For service principal auth (optional)
AZURE_CLIENT_SECRET=<client-secret> # For service principal auth (optional)
Authentication
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Sql;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var armClient = new ArmClient(credential);
// Get subscription
var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
var subscription = armClient.GetSubscriptionResource(
new ResourceIdentifier($"/subscriptions/{subscriptionId}"));
Resource Hierarchy
ArmClient
└── SubscriptionResource
└── ResourceGroupResource
└── SqlServerResource
├── SqlDatabaseResource
├── ElasticPoolResource
│ └── ElasticPoolDatabaseResource
├── SqlFirewallRuleResource
├── FailoverGroupResource
├── ServerBlobAuditingPolicyResource
├── EncryptionProtectorResource
└── VirtualNetworkRuleResource
Core Workflow
1. Create SQL Server
using Azure.ResourceManager.Sql;
using Azure.ResourceManager.Sql.Models;
// Get resource group
var resourceGroup = await subscription
.GetResourceGroupAsync("my-resource-group");
// Define server
var serverData = new SqlServerData(AzureLocation.EastUS)
{
AdministratorLogin = "sqladmin",
AdministratorLoginPassword = "YourSecurePassword123!",
Version = "12.0",
MinimalTlsVersion = SqlMinimalTlsVersion.Tls1_2,
PublicNetworkAccess = ServerNetworkAccessFlag.Enabled
};
// Create server (long-running operation)
var serverCollection = resourceGroup.Value.GetSqlServers();
var operation = await serverCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"my-sql-server",
serverData);
SqlServerResource server = operation.Value;
2. Create SQL Database
var databaseData = new SqlDatabaseData(AzureLocation.EastUS)
{
Sku = new SqlSku("S0") { Tier = "Standard" },
MaxSizeBytes = 2L * 1024 * 1024 * 1024, // 2 GB
Collation = "SQL_Latin1_General_CP1_CI_AS",
RequestedBackupStorageRedundancy = SqlBackupStorageRedundancy.Local
};
var databaseCollection = server.GetSqlDatabases();
var dbOperation = await databaseCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"my-database",
databaseData);
SqlDatabaseResource database = dbOperation.Value;
3. Create Elastic Pool
var poolData = new ElasticPoolData(AzureLocation.EastUS)
{
Sku = new SqlSku("StandardPool")
{
Tier = "Standard",
Capacity = 100 // 100 eDTUs
},
PerDatabaseSettings = new ElasticPoolPerDatabaseSettings
{
MinCapacity = 0,
MaxCapacity = 100
}
};
var poolCollection = server.GetElasticPools();
var poolOperation = await poolCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"my-elastic-pool",
poolData);
ElasticPoolResource pool = poolOperation.Value;
4. Add Database to Elastic Pool
var databaseData = new SqlDatabaseData(AzureLocation.EastUS)
{
ElasticPoolId = pool.Id
};
await databaseCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"pooled-database",
databaseData);
5. Configure Firewall Rules
// Allow Azure services
var azureServicesRule = new SqlFirewallRuleData
{
StartIPAddress = "0.0.0.0",
EndIPAddress = "0.0.0.0"
};
var firewallCollection = server.GetSqlFirewallRules();
await firewallCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"AllowAzureServices",
azureServicesRule);
// Allow specific IP range
var clientRule = new SqlFirewallRuleData
{
StartIPAddress = "203.0.113.0",
EndIPAddress = "203.0.113.255"
};
await firewallCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"AllowClientIPs",
clientRule);
6. List Resources
// List all servers in subscription
await foreach (var srv in subscription.GetSqlServersAsync())
{
Console.WriteLine($"Server: {srv.Data.Name} in {srv.Data.Location}");
}
// List databases in a server
await foreach (var db in server.GetSqlDatabases())
{
Console.WriteLine($"Database: {db.Data.Name}, SKU: {db.Data.Sku?.Name}");
}
// List elastic pools
await foreach (var ep in server.GetElasticPools())
{
Console.WriteLine($"Pool: {ep.Data.Name}, DTU: {ep.Data.Sku?.Capacity}");
}
7. Get Connection String
// Build connection string (server FQDN is predictable)
var serverFqdn = $"{server.Data.Name}.database.windows.net";
var connectionString = $"Server=tcp:{serverFqdn},1433;" +
$"Initial Catalog={database.Data.Name};" +
"Persist Security Info=False;" +
$"User ID={server.Data.AdministratorLogin};" +
"Password=<your-password>;" +
"MultipleActiveResultSets=False;" +
"Encrypt=True;" +
"TrustServerCertificate=False;" +
"Connection Timeout=30;";
Key Types Reference
| Type | Purpose |
|---|---|
ArmClient | Entry point for all ARM operations |
SqlServerResource | Represents an Azure SQL server |
SqlServerCollection | Collection for server CRUD |
SqlDatabaseResource | Represents a SQL database |
SqlDatabaseCollection | Collection for database CRUD |
ElasticPoolResource | Represents an elastic pool |
ElasticPoolCollection | Collection for elastic pool CRUD |
SqlFirewallRuleResource | Represents a firewall rule |
SqlFirewallRuleCollection | Collection for firewall rule CRUD |
SqlServerData | Server creation/update payload |
SqlDatabaseData | Database creation/update payload |
ElasticPoolData | Elastic pool creation/update payload |
SqlFirewallRuleData | Firewall rule creation/update payload |
SqlSku | SKU configuration (tier, capacity) |
Common SKUs
Database SKUs
| SKU Name | Tier | Description |
|---|---|---|
Basic | Basic | 5 DTUs, 2 GB max |
S0-S12 | Standard | 10-3000 DTUs |
P1-P15 | Premium | 125-4000 DTUs |
GP_Gen5_2 | GeneralPurpose | vCore-based, 2 vCores |
BC_Gen5_2 | BusinessCritical | vCore-based, 2 vCores |
HS_Gen5_2 | Hyperscale | vCore-based, 2 vCores |
Elastic Pool SKUs
| SKU Name | Tier | Description |
|---|---|---|
BasicPool | Basic | 50-1600 eDTUs |
StandardPool | Standard | 50-3000 eDTUs |
PremiumPool | Premium | 125-4000 eDTUs |
GP_Gen5_2 | GeneralPurpose | vCore-based |
BC_Gen5_2 | BusinessCritical | vCore-based |
Best Practices
- Use
WaitUntil.Completedfor operations that must finish before proceeding - Use
WaitUntil.Startedwhen you want to poll manually or run operations in parallel - Always use
DefaultAzureCredential— never hardcode passwords in production - Handle
RequestFailedExceptionfor ARM API errors - Use
CreateOrUpdateAsyncfor idempotent operations - Navigate hierarchy via
Get*methods (e.g.,server.GetSqlDatabases()) - Use elastic pools for cost optimization when managing multiple databases
- Configure firewall rules before attempting connections
Error Handling
using Azure;
try
{
var operation = await serverCollection.CreateOrUpdateAsync(
WaitUntil.Completed, serverName, serverData);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
Console.WriteLine("Server already exists");
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
Console.WriteLine($"Invalid request: {ex.Message}");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"ARM Error: {ex.Status} - {ex.ErrorCode}: {ex.Message}");
}
Reference Files
| File | When to Read |
|---|---|
| references/server-management.md | Server CRUD, admin credentials, Azure AD auth, networking |
| references/database-operations.md | Database CRUD, scaling, backup, restore, copy |
| references/elastic-pools.md | Pool management, adding/removing databases, scaling |
Related SDKs
| SDK | Purpose | Install |
|---|---|---|
Microsoft.Data.SqlClient | Data plane (execute queries, stored procedures) | dotnet add package Microsoft.Data.SqlClient |
Azure.ResourceManager.Sql | Management plane (this SDK) | dotnet add package Azure.ResourceManager.Sql |
Microsoft.EntityFrameworkCore.SqlServer | ORM for SQL Server | dotnet add package Microsoft.EntityFrameworkCore.SqlServer |
microsoft की और Skills
oss-growth
microsoft
OSS ग्रोथ हैकर व्यक्तित्व
official
microsoft-foundry
microsoft
Foundry एजेंटों को एंड-टू-एंड डिप्लॉय, मूल्यांकन और प्रबंधित करें: Docker बिल्ड, ACR पुश, होस्टेड/प्रॉम्प्ट एजेंट क्रिएट, कंटेनर स्टार्ट, बैच इवैल्यूएशन, कंटीन्यूअस इवैल्यूएशन, प्रॉम्प्ट ऑप्टिमाइज़र वर्कफ़्लो, agent.yaml, ट्रेस से डेटासेट क्यूरेशन। इसका उपयोग करें: Foundry पर एजेंट डिप्लॉय करना, होस्टेड एजेंट, एजेंट बनाना, एजेंट को इनवोक करना, एजेंट का मूल्यांकन
officialdevelopmentdevops
azure-ai
microsoft
Azure AI के लिए उपयोग करें: खोज, वाक्, OpenAI, दस्तावेज़ बुद्धिमत्ता। खोज, वेक्टर/हाइब्रिड खोज, वाक्-से-पाठ, पाठ-से-वाक्, प्रतिलेखन, OCR में सहायता करता है। कब उपयोग करें: AI खोज, क्वेरी खोज, वेक्टर खोज, हाइब्रिड खोज, सिमैंटिक खोज, वाक्-से-पाठ, पाठ-से-वाक्, प्रतिलेखन, OCR, पाठ को वाक् में बदलना।
officialdevelopmentapi
azure-deploy
microsoft
पहले से तैयार एप्लिकेशनों के लिए Azure डिप्लॉयमेंट निष्पादित करें जिनमें मौजूदा .azure/deployment-plan.md और इंफ्रास्ट्रक्चर फ़ाइलें हों। इस स्किल का उपयोग तब न करें जब उपयोगकर्ता कोई नया एप्लिकेशन बनाने के लिए कहे — इसके बजाय azure-prepare का उपयोग करें। यह स्किल azd up, azd deploy, terraform apply, और az deployment कमांड को बिल्ट-इन एरर रिकवरी के साथ चलाती है। इसके लिए azure-prepare से .azure/deployment-plan.md और azure-validate से सत्यापित स्थिति आवश्यक है। कब: "azd
officialdevopsaws
azure-storage
microsoft
Azure Storage सेवाएँ जिनमें Blob Storage, File Shares, Queue Storage, Table Storage और Data Lake शामिल हैं। स्टोरेज एक्सेस टियर (हॉट, कूल, कोल्ड, आर्काइव), प्रत्येक टियर का उपयोग कब करें और टियर तुलना के बारे में प्रश्नों के उत्तर देता है। ऑब्जेक्ट स्टोरेज, SMB फ़ाइल शेयर, एसिंक्रोनस मैसेजिंग, NoSQL की-वैल्यू और बिग डेटा एनालिटिक्स प्रदान करता है। लाइफसाइकिल प्रबंधन शामिल है। उपयोग करें: ब्लॉब स्टोरेज, फ़ाइल शेयर, क्य
officialdevelopmentdatabase
azure-diagnostics
microsoft
Azure पर AppLens, Azure Monitor, संसाधन स्वास्थ्य और सुरक्षित ट्राइएज का उपयोग करके Azure उत्पादन समस्याओं को डीबग करें। कब: उत्पादन समस्याओं को डीबग करना, ऐप सेवा समस्या निवारण, ऐप सेवा उच्च CPU, ऐप सेवा परिनियोजन विफलता, कंटेनर ऐप्स समस्या निवारण, फंक्शन्स समस्या निवारण, AKS समस्या निवारण, kubectl कनेक्ट नहीं हो सकता, kube-system/CoreDNS विफलताएँ, पॉड लंबित, क्रैशलूप, नोड तैयार नहीं, अपग्रेड विफ
officialdevopsdevelopment
azure-prepare
microsoft
Azure ऐप्स को तैनाती के लिए तैयार करें (infra Bicep/Terraform, azure.yaml, Dockerfiles)। निर्माण/आधुनिकीकरण या निर्माण+तैनाती के लिए उपयोग करें; क्रॉस-क्लाउड माइग्रेशन के लिए नहीं (azure-cloud-migrate का उपयोग करें)। इसका उपयोग न करें: copilot-sdk ऐप्स के लिए (azure-hosted-copilot-sdk का उपयोग करें)। कब: "create app", "build web app", "create API", "create serverless HTTP API", "create frontend", "create back end", "build a service", "modernize application", "update application", "add authentication", "add caching", "host on Azure", "create and...
officialdevelopmentdevops
azure-validate
microsoft
Azure तैनाती-पूर्व तत्परता के लिए सत्यापन। तैनाती से पहले कॉन्फ़िगरेशन, इंफ्रास्ट्रक्चर (Bicep या Terraform), RBAC भूमिका असाइनमेंट, प्रबंधित पहचान अनुमतियाँ और पूर्वापेक्षाओं की गहन जाँच करें। कब: मेरे ऐप को सत्यापित करें, तैनाती तत्परता की जाँच करें, प्रीफ्लाइट जाँच चलाएँ, कॉन्फ़िगरेशन सत्यापित करें, तैनाती के लिए तैयार है या नहीं जाँचें, azure.yaml सत्यापित करें, Bicep सत्यापित
officialdevopstesting