Skip to content

Latest commit

 

History

History
57 lines (43 loc) · 3.37 KB

porting-cheat-sheet.md

File metadata and controls

57 lines (43 loc) · 3.37 KB

Cheat sheet for porting from System.Data.SqlClient to Microsoft.Data.SqlClient

This guide is meant to cover all namespace changes needed in client applications when porting SqlClient references to Microsoft.Data.SqlClient:

Namespace Changes needed

Microsoft.Data.SqlClient v5.0 and newer

Namespace Change Applicability
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
Applicable to all classes, enums and delegates.
using Microsoft.SqlServer.Server;
using Microsoft.Data.SqlClient.Server;
Applicable Classes:
SqlDataRecord
SqlMetaData

1 All remaining types continue to be referenced from Microsoft.SqlServer.Server namespace.
using System.Data.SqlTypes;
using Microsoft.Data.SqlTypes;
Applicable Classes:
SqlFileStream
using System.Data.Sql;
using Microsoft.Data.Sql;
Applicable Classes:
SqlNotificationRequest
using System.Data;
using Microsoft.Data;
Applicable Classes:
OperationAbortedException

1 Breaking change for User-Defined types and Microsoft.SqlServer.Types support over Microsoft.Data.SqlClient v3.0.0.

Microsoft.Data.SqlClient v4.0 and older

Namespace Change Applicability
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
Applicable to all classes, enums and delegates.
using Microsoft.SqlServer.Server;
using Microsoft.Data.SqlClient.Server;
Applicable Classes:
InvalidUdtException
SqlDataRecord
SqlFunctionAttribute
SqlMetaData
SqlMethodAttribute
SqlUserDefinedAggregateAttribute
SqlUserDefinedTypeAttribute

Applicable Interfaces:
IBinarySerialize

Applicable Enums:
DataAccessKind
Format
SystemDataAccessKind
using System.Data.SqlTypes;
using Microsoft.Data.SqlTypes;
Applicable Classes:
SqlFileStream
using System.Data.Sql;
using Microsoft.Data.Sql;
Applicable Classes:
SqlNotificationRequest
using System.Data;
using Microsoft.Data;
Applicable Classes:
OperationAbortedException

Configuration

For .NET Framework projects it may be necessary to include the following in your App.config or Web.config file:

<configuration>
    ...
    <system.data>
        <DbProviderFactories>
            <add name="SqlClient Data Provider"
                invariant="Microsoft.Data.SqlClient"
                description=".Net Framework Data Provider for SqlServer" 
                type="Microsoft.Data.SqlClient.SqlClientFactory, Microsoft.Data.SqlClient" />
        </DbProviderFactories>
    </system.data>
    ...
</configuration>

Functionality Changes

System.Data.SqlClient Microsoft.Data.SqlClient
Can use DateTime object as value for SqlParameter with type DbType.Time. Must use TimeSpan object as value for SqlParameter with type DbType.Time.
Using DateTime object as value for SqlParameter with type DbType.Date would send date and time to SQL Server. DateTime object's time components will be truncated when sent to SQL Server using DbType.Date.

Contribute to this Cheat Sheet

We would love the SqlClient community to help enhance this cheat sheet by contributing experiences and challenges faced when porting their applications.