microsoft/migrating-to-microsoft-data-sqlclient
> Migrates .NET projects from System.Data.SqlClient to Microsoft.Data.SqlClient, handling package references, namespace updates, connection string encryption changes, and behavioral differences. Use when upgrading SqlClient, replacing System.Data.SqlClient, migrating to Microsoft.Data.SqlClient, or modernizing SQL Server data access in C# or VB.NET projects (.csproj, .vbproj, .cs, .vb files).
npx skills add https://github.com/microsoft/upgrade-agent-plugins --skill migrating-to-microsoft-data-sqlclient
Migrate .NET projects from System.Data.SqlClient to Microsoft.Data.SqlClient, covering package references, code files, connection string validation, and configuration changes. The migration includes documenting behavioral differences that require runtime verification.
System.Data.SqlClientNuGet package names and assembly names are case-insensitive. Account for this when searching for or removing dependencies to avoid missed references.
Complete all steps without pausing between them. Each step builds on the previous one, and partial migration leaves the codebase in a broken state.
Migration Progress:
- [ ] Step 1: Update package dependencies
- [ ] Step 2: Update code files
- [ ] Step 3: Validate migration (repeat Steps 2-3 until clean)
- [ ] Step 4: Build verification
- [ ] Step 5: Connection string validation
For each project with an explicit dependency on System.Data.SqlClient in the project file or imported MSBuild targets (skip projects receiving it transitively — adding a new direct reference would create unnecessary coupling):
System.Data.SqlClient package reference and assembly referenceMicrosoft.Data.SqlClient with a version supporting the project's target framework. Use available tools to determine the best version; fall back to manual determination only if no tool is availableSystem.Data.SqlClient from Directory.Packages.props. Add Microsoft.Data.SqlClient as a PackageVersion element in Directory.Packages.props and a version-less PackageReference in the project fileSearch the affected projects and projects that depend on them (transitive consumers may reference System.Data.SqlClient types). Use search tools and pass root folders for all relevant projects.
System.Data.SqlClient usages with Microsoft.Data.SqlClient equivalents. Preserve all business logic — never insert placeholdersSystem.Data.SqlClient namespace (skip comments and string literal constants)System.Data.SqlClient API usage remains in the file, replace the using; if no other usage exists, remove the using instead of replacing it. Do not add Microsoft.Data.SqlClient usings to files that had no System.Data.SqlClient usingsSearch for System.Data.SqlClient across all affected projects and their dependents. If any references remain, return to Step 2. Repeat until no System.Data.SqlClient references exist.
Build all modified projects. Fix all build errors before proceeding — a partial fix leaves the codebase unusable.
Search for connection strings in app.config, web.config, and appsettings.json across affected projects and dependents. For connection strings pointing to databases:
Encrypt or TrustServerCertificate are not explicitly set, flag for the user — defaults changed (see Key Behavioral Differences below)Encrypt is a bool value and the target is Microsoft.Data.SqlClient v5.0+, convert it to the corresponding SqlConnectionEncryptOption enum value and flag for user validationThese differences cause silent runtime behavior changes. Flag them in the migration report.
Encrypt defaults to falseEncrypt defaults to trueEncrypt is a SqlConnectionEncryptOption enum (Optional, Mandatory, Strict), no longer a boolEncrypt was trueTrustServerCertificateTrustServerCertificate=trueDbType.Time: System.Data.SqlClient accepts DateTime; Microsoft.Data.SqlClient requires TimeSpanDbType.Date: System.Data.SqlClient sends date and time; Microsoft.Data.SqlClient truncates time components| Old Namespace | New Namespace |
|---|---|
| System.Data.SqlClient.* | Microsoft.Data.SqlClient.* |
| Microsoft.SqlServer.Server.SqlDataRecord | Microsoft.Data.SqlClient.Server.SqlDataRecord |
| Microsoft.SqlServer.Server.SqlMetaData | Microsoft.Data.SqlClient.Server.SqlMetaData |
| System.Data.SqlTypes.SqlFileStream | Microsoft.Data.SqlTypes.SqlFileStream |
| System.Data.Sql.SqlNotificationRequest | Microsoft.Data.Sql.SqlNotificationRequest |
| System.Data.OperationAbortedException | Microsoft.Data.OperationAbortedException |
System.Data.SqlClient references remain in affected projectsTake microsoft/migrating-to-microsoft-data-sqlclient from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.