| 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 |
Our XML documentation is ingested into dotnet/sqlclient-api-docs, where Open Publishing resolves every cref against the Learn xref map. A malformed documentation ID cannot resolve and produces an xref-not-found warning on the API Docs pull request, long after the change left this repository.
A cref may be written unqualified (<see cref="SqlConnection.Open"/>), in which case the compiler binds it from the surrounding source. Once you write an explicit T:/M:/P:/F:/E:/N: prefix, the compiler passes the value through verbatim and no longer checks it, so the rules below are yours to get right.
| Rule | Wrong | Right |
|---|---|---|
| Use CLR type names, not C# aliases | M:...GetSchema(string) |
M:...GetSchema(System.String) |
| Omit parentheses on a parameterless member | M:...GetSchema() |
M:...GetSchema |
| Never include whitespace | M:...Add(System.String, System.String) |
M:...Add(System.String,System.String) |
T: names a type, never an array |
T:System.Byte[] |
T:System.Byte array |
| Match the prefix to the member kind | M:...SqlCommand.CommandTimeout |
P:...SqlCommand.CommandTimeout |
| Generic arguments use braces | T:...List<System.String> |
T:...List{System.String} |
Array, pointer and by-reference markers are legal inside a member signature (M:...Decrypt(System.Byte[])); they are only invalid as the whole target of a T: reference.
Markdown inside <format type="text/markdown"> uses <xref:UID> tokens rather than cref
attributes. The compiler copies these tokens verbatim and cannot validate them. A parameterized
method has no bare UID, even when it has only one overload, so link to its overload page with the
URL-encoded wildcard %2A:
<!-- Wrong: Open Publishing looks for an exact UID that does not exist. -->
<xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer>
<!-- Right: links to the method's overload page. -->
<xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A>Types, properties, fields, events, and parameterless methods may continue to use their exact bare UIDs. Generated-document validation indexes the emitted members and rejects a bare inline xref when that index proves the target is a parameterized method.
eng/pipelines/common/scripts/validate-xml-docs.ps1 enforces the rules above. OneBranch uses it
against snippet sources, generated documentation, and assembled packages; the PR pipeline uses it
against snippets and assembled packages. Run it before pushing documentation changes:
./eng/pipelines/common/scripts/validate-xml-docs.ps1 -SnippetsDirectory ./doc/snippetsTo also resolve references against the members the build actually emitted, which additionally catches wrong-kind prefixes and cross-references the compiler failed to bind:
dotnet build ./src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.csproj -c Release
./eng/pipelines/common/scripts/validate-xml-docs.ps1 -DocumentationPath ./artifacts/Microsoft.Data.SqlClient.ref/Project-ReleaseUse the configuration-specific directory so stale outputs from another reference mode or build configuration are not included in the result.
Validation is offline by design; it needs no network access and no xref map download.
Local validation proves that XML is well formed and that references resolve, but it does not prove that Open Publishing rendered every documentation element. After an API docs ingestion PR is available in dotnet/sqlclient-api-docs, compare the Learn previews with the source XML before approving the update.
-
Find the latest Learn Build status comment and record the commit it validated. Do not use preview links from an older comment.
-
Enumerate every changed API XML file in the PR. The bot comment lists only the first 25 files, including framework indexes and package metadata, so its table is not the complete API-page list:
gh api repos/dotnet/sqlclient-api-docs/pulls/<pr>/files --paginate \ --jq '.[] | select(.filename | test("/xml/.+/.+\\.xml$")) | .filename'
-
Open every API type preview. Use the
FullNamefrom the file's<Type>element as the lowercase API slug, preserve thebranch=pr-en-us-<pr>query, and select the matching view:- Main provider:
sqlclient-dotnet-core-<version> - Azure Key Vault provider:
akvprovider-dotnet-core-<version>
- Main provider:
-
Follow the preview's own links to every changed member or overload. Do not derive explicit-interface or operator URLs by string replacement; Learn uses special slugs for some members. Enum fields intentionally have no standalone pages and must be checked in the type's fields table.
-
Compare the rendered content through the entire publication path:
- Local snippet or source XML
- The
<include>path on the public declaration - Generated or packaged XML documentation
- The API docs PR XML
- The rendered type and member previews
-
Check summaries, remarks, examples, parameters, returns or values, exceptions, overload descriptions, code samples, and xrefs. A healthy type landing page is not proof that each overload page is complete.
-
Classify expected renderer transformations before reporting a discrepancy:
- Learn adds display signatures to xrefs, such as
GetSchema(). - Markdown tables become separate cells and included snippets become rendered code.
To be added.placeholders are suppressed.<remarks>on enum fields are discarded; move required text into<summary>.
- Learn adds display signatures to xrefs, such as
-
Treat content present in a snippet but absent from generated XML as a source or build-wiring problem. Common causes include an
<include>XPath that matches nothing or too much, documentation attached only to a ref declaration, andlib/packaging from trimmedref/XML.
The review site requires Microsoft authentication. On a corp-joined Windows device running WSL, the Linux browser may not have the required session. Launch a separate Windows Edge profile with Chrome DevTools Protocol enabled so Edge can use seamless Entra SSO:
EDGE="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
"$EDGE" --remote-debugging-port=9222 --remote-allow-origins=http://localhost:9222 \
--user-data-dir=C:\\Temp\\edge-cdp-profile \
--no-first-run --no-default-browser-check about:blankOmit --remote-allow-origins when the CDP client sends no Origin header. Otherwise, allow only
the exact origin used by that client; never use a wildcard with an authenticated browser profile.
Drive the browser from the Windows side because the Windows firewall can block WSL-to-Windows access to the debugging port:
/mnt/c/Windows/System32/curl.exe -s http://localhost:9222/json/version
/mnt/c/Windows/System32/curl.exe -s http://localhost:9222/jsonNever automate credentials or copy authentication tokens. Navigate the authenticated browser through CDP and capture the rendered article text or DOM for comparison. Keep crawl output outside the repository.
The driver package ships two XML documentation files per target framework, and they are deliberately different:
| Package folder | Content | Consumer |
|---|---|---|
lib/<tfm>/ |
Full documentation, including <remarks> and <example> |
The .NET API docs pipeline, which builds the Learn pages |
ref/<tfm>/ |
Trimmed by tools/intellisense/TrimDocs.ps1, which strips <remarks> and <example> |
Visual Studio IntelliSense |
Remarks and examples render poorly in Visual Studio tooltips, which is why the ref/ copy is trimmed. The two files must never be the same: if lib/ is sourced from the trimmed artifact, the published Learn pages silently lose every remark and example. That regression shipped in 7.1.0, so the packaged-documentation gate now fails the build when a package's lib/ XML is trimmed, its ref/ XML is not, or the two are byte-identical.
When changing the <file> mappings in Microsoft.Data.SqlClient.nuspec, keep lib/ pointed at the implementation artifact and ref/ at the reference artifact.
- 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