Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare Azure environments for new workloads—subscriptions, networking, identity, and landing zones
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/sql-database/sdk.md
1# SQL Database - SDK Patterns23## Node.js (mssql)45```javascript6const sql = require('mssql');78const config = {9server: process.env.SQL_SERVER,10database: process.env.SQL_DATABASE,11authentication: {12type: 'azure-active-directory-default'13},14options: {15encrypt: true16}17};1819const pool = await sql.connect(config);20```2122## Python (pyodbc)2324> **Auth:** `DefaultAzureCredential` is for local development. See [auth-best-practices.md](../../auth-best-practices.md) for production patterns.2526```python27import pyodbc28from azure.identity import DefaultAzureCredential2930credential = DefaultAzureCredential()31token = credential.get_token("https://database.windows.net/.default")3233conn = pyodbc.connect(34f"Driver={{ODBC Driver 18 for SQL Server}};"35f"Server={os.environ['SQL_SERVER']};"36f"Database={os.environ['SQL_DATABASE']};"37f"Authentication=ActiveDirectoryMsi"38)39```4041## .NET (Entity Framework Core)4243**Required NuGet Packages:**44```bash45dotnet add package Microsoft.EntityFrameworkCore.SqlServer46dotnet add package Microsoft.Data.SqlClient --version 5.1.047dotnet add package Azure.Identity48```4950**Connection string (Entra ID):**51```52Server=tcp:{server}.database.windows.net,1433;Database={database};Authentication=Active Directory Default;Encrypt=True;53```5455**Configuration:**56```csharp57services.AddDbContext<AppDbContext>(options =>58options.UseSqlServer(59Configuration.GetConnectionString("DefaultConnection"),60sqlOptions => sqlOptions.EnableRetryOnFailure()61));62```6364**appsettings.json:**65```json66{67"ConnectionStrings": {68"DefaultConnection": "Server=tcp:myserver.database.windows.net,1433;Database=mydb;Authentication=Active Directory Default;Encrypt=True;"69}70}71```7273## Connection String Format7475```76Server=tcp:{server}.database.windows.net,1433;Database={database};Authentication=Active Directory Default;Encrypt=True;77```78