| applyTo | doc/**,**/samples/** |
|---|
doc/
├── Directory.Packages.props # Package versions for doc projects
├── samples/ # Code samples for documentation
│ ├── AADAuthenticationCustomDeviceFlowCallback.cs
│ ├── AzureKeyVaultProviderExample.cs
│ ├── ConnectionStrings_Encrypt.cs
│ └── ...
└── snippets/ # Documentation snippets
Use descriptive names following the pattern:
{ClassName}_{MethodOrFeature}.cs
{FeatureName}_Example.cs
{ClassName}_{Scenario}.cs
Examples:
SqlConnection_Open.csSqlBulkCopy_ColumnMapping.csAlwaysEncrypted_AzureKeyVault.cs
// <Snippet1>
using System;
using System.Data;
using Microsoft.Data.SqlClient;
class Program
{
static void Main()
{
// Sample code here
}
}
// </Snippet1>Use XML comment tags to define reusable snippets:
// <Snippet_OpenConnection>
using var connection = new SqlConnection(connectionString);
connection.Open();
Console.WriteLine($"Connected to: {connection.Database}");
// </Snippet_OpenConnection>Demonstrate connection scenarios:
- Basic connection
- Connection string building
- Authentication methods
- Connection pooling
Show command execution:
- ExecuteReader
- ExecuteNonQuery
- ExecuteScalar
- Async execution
- Parameterized queries
Transaction management:
- Local transactions
- Distributed transactions (MSDTC)
- SavePoints
Working with SQL data types:
- DateTime handling
- Binary data
- XML data
- JSON (SQL Server 2025+)
- Vector (SQL Server 2025+)
Authentication and encryption:
- Entra ID authentication
- Always Encrypted
- Azure Key Vault integration
- SSL/TLS configuration
Optimization techniques:
- Bulk copy operations
- Async patterns
- Connection pooling
- Batch operations
All public APIs must have XML documentation:
/// <summary>
/// Opens a database connection with the settings specified by the
/// <see cref="ConnectionString"/> property.
/// </summary>
/// <exception cref="InvalidOperationException">
/// A connection was already open.
/// </exception>
/// <exception cref="SqlException">
/// A connection-level error occurred while opening the connection.
/// </exception>
/// <example>
/// <code>
/// using var connection = new SqlConnection(connectionString);
/// connection.Open();
/// </code>
/// </example>
public override void Open()| Element | Usage |
|---|---|
<summary> |
Brief description (required) |
<param> |
Parameter description |
<returns> |
Return value description |
<exception> |
Exceptions that may be thrown |
<example> |
Usage example |
<remarks> |
Additional details |
<seealso> |
Related members |
- Use third person ("Opens a connection" not "Open a connection")
- Be concise but complete
- Include common use cases
- Note any platform-specific behavior
// Use meaningful variable names
using var connection = new SqlConnection(connectionString);
// Include error handling in samples
try
{
connection.Open();
}
catch (SqlException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
// Show proper resource cleanup
using var reader = command.ExecuteReader();
// Use async when demonstrating async features
await connection.OpenAsync();// Don't use hardcoded credentials
var conn = "Server=x;User=sa;Password=secret"; // BAD!
// Don't leave resources unmanaged
var reader = cmd.ExecuteReader(); // Missing using/Dispose
// Don't suppress exceptions silently
try { ... } catch { } // BAD!- Create sample file in
doc/samples/ - Follow naming convention for discoverability
- Use snippet tags for documentation inclusion
- Test the sample to ensure it compiles and runs
- Link from documentation where relevant
Samples should be testable:
// Sample helper for testing
public static class SampleRunner
{
public static string ConnectionString =>
Environment.GetEnvironmentVariable("SQLCLIENT_TEST_CONNSTR")
?? "Server=localhost;Database=master;Trusted_Connection=True;";
}Samples may be referenced from Microsoft Learn documentation:
When creating samples for external documentation:
- Verify snippet tags are correctly formatted
- Ensure sample compiles standalone
- Include all necessary using statements
- Document any prerequisites
Do not edit CHANGELOG.md directly. The changelog is updated as part of the release workflow based on the contents of release-notes/ and the release-notes prompt.
When adding features, fixes, or breaking changes, create or update the appropriate entry under release-notes/ instead. For example:
## [Unreleased]
### Added
- New `SqlCommand.ExecuteJsonAsync()` method for JSON result sets
- Support for SQL Server 2025 JSON data type
### Changed
- Connection encryption now defaults to Mandatory
### Fixed
- Issue with connection pool exhaustion under high load (#1234)
### Deprecated
- `SqlConnection.GetSchema(string)` overloadRelease notes in release-notes/ follow version structure:
release-notes/
├── README.md # Index of all versions
├── 5.0/ # Major version folder
│ └── 5.0.md # Version release notes
├── 5.1/
│ └── 5.1.md
└── template/ # Release notes template