Skip to content

Commit efa4636

Browse files
committed
docs: Migrate System.Data.SqlClient to Microsoft.Data.SqlClient in CLR UDT/UDA articles
1 parent 81b3a58 commit efa4636

4 files changed

Lines changed: 50 additions & 48 deletions

File tree

docs/relational-databases/clr-integration-database-objects-user-defined-functions/clr-user-defined-aggregate-invoking-functions.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Invoking CLR User-Defined Aggregate Functions"
33
description: In SQL Server CLR integration, use Transact-SQL SELECT to invoke CLR user-defined aggregates, subject to the rules that apply to system aggregate functions.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: 12/27/2024
6+
ms.date: 03/19/2026
77
ms.service: sql
88
ms.subservice: clr
99
ms.topic: "reference"
@@ -26,7 +26,7 @@ The following additional rules apply:
2626

2727
- The current user must have `EXECUTE` permission on the user-defined aggregate.
2828

29-
- User-defined aggregates must be invoked using a two-part name in the form of <schema_name>.<udagg_name>.
29+
- User-defined aggregates must be invoked by using a two-part name in the form of <schema_name>.<udagg_name>.
3030

3131
- The argument type of the user-defined aggregate must match or be implicitly convertible to the *input_type* of the aggregate, as defined in the `CREATE AGGREGATE` statement.
3232

@@ -210,7 +210,7 @@ CREATE AGGREGATE MyAgg(@input NVARCHAR (200))
210210
> [!NOTE]
211211
> Visual C++ database objects, such as scalar-valued functions, that have been compiled with the `/clr:pure` compiler option aren't supported for execution in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)].
212212
213-
As with most aggregates, the bulk of the logic is in the `Accumulate` method. Here, the string that is passed in as a parameter to the `Accumulate` method is appended to the `StringBuilder` object that was initialized in the `Init` method. Assuming that the `Accumulate` method wasn't already called, a comma is also appended to the `StringBuilder` before appending the passed-in string. At the conclusion of the computational tasks, the `Terminate` method is called, which returns the `StringBuilder` as a string.
213+
As with most aggregates, the bulk of the logic is in the `Accumulate` method. Here, the string that is passed in as a parameter to the `Accumulate` method is appended to the `StringBuilder` object that was initialized in the `Init` method. Assuming that the `Accumulate` method wasn't already called, a comma is also appended to the `StringBuilder` before appending the passed-in string. When computation finishes, the `Terminate` method is called, which returns the `StringBuilder` as a string.
214214

215215
For example, consider a table with the following schema:
216216

@@ -258,7 +258,6 @@ The following sample shows an aggregate that has two parameters on the `Accumula
258258
```csharp
259259
using System;
260260
using System.Data;
261-
using System.Data.SqlClient;
262261
using System.Data.SqlTypes;
263262
using Microsoft.SqlServer.Server;
264263

@@ -339,7 +338,6 @@ public struct WeightedAvg
339338
```vb
340339
Imports System
341340
Imports System.Data
342-
Imports System.Data.SqlClient
343341
Imports System.Data.SqlTypes
344342
Imports Microsoft.SqlServer.Server
345343
Imports System.Runtime.InteropServices
@@ -411,7 +409,7 @@ End Class
411409

412410
---
413411

414-
After you compile the [!INCLUDE [c-sharp-md](../../includes/c-sharp-md.md)] or [!INCLUDE [visual-basic-md](../../includes/visual-basic-md.md)] .NET source code, run the following [!INCLUDE [tsql](../../includes/tsql-md.md)]. This script assumes that the DLL is called WghtAvg.dll and is in the root directory of your C drive. A database called test is also assumed.
412+
After you compile the [!INCLUDE [c-sharp-md](../../includes/c-sharp-md.md)] or [!INCLUDE [visual-basic-md](../../includes/visual-basic-md.md)] .NET source code, run the following [!INCLUDE [tsql](../../includes/tsql-md.md)]. This script assumes that the DLL is called WghtAvg.dll and is in the root directory of your C drive. It also assumes a database called test exists.
415413

416414
```sql
417415
USE test;

docs/relational-databases/clr-integration-database-objects-user-defined-types/accessing-user-defined-types-in-ado-net.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Accessing User-Defined Types in ADO.NET"
33
description: UDTs, written in .NET Framework CLR languages, allow a SQL Server database to store objects and custom data structures. In ADO.NET, a provider exposes UDTs.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: 12/27/2024
6+
ms.date: 03/19/2026
77
ms.service: sql
88
ms.subservice: clr
99
ms.topic: "reference"
@@ -20,11 +20,11 @@ User-defined types (UDTs) are written using any of the languages supported by th
2020

2121
The data is exposed as public members of a .NET Framework class or structure, and behaviors are defined by methods of the class or structure. A UDT can be used as the column definition of a table, as a variable in a [!INCLUDE [tsql](../../includes/tsql-md.md)] batch, or as an argument of a [!INCLUDE [tsql](../../includes/tsql-md.md)] function or stored procedure.
2222

23-
In ADO.NET, the `System.Data.SqlClient` provider exposes UDTs in the following ways:
23+
In ADO.NET, the `Microsoft.Data.SqlClient` provider exposes UDTs in the following ways:
2424

25-
- Through the `System.Data.SqlClient.SqlDataReader` as an object.
25+
- Through the `Microsoft.Data.SqlClient.SqlDataReader` as an object.
2626
- Through the `SqlDataReader` as raw bytes.
27-
- As a parameter of a `System.Data.SqlClient.SqlParameter` object.
27+
- As a parameter of a `Microsoft.Data.SqlClient.SqlParameter` object.
2828

2929
## In this section
3030

docs/relational-databases/clr-integration-database-objects-user-defined-types/accessing-user-defined-types-retrieving-udt-data.md

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Retrieving UDT Data"
33
description: This article describes how to access UDTs in a SQL Server database.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: 12/27/2024
6+
ms.date: 03/19/2026
77
ms.service: sql
88
ms.subservice: clr
99
ms.topic: "reference"
@@ -25,20 +25,26 @@ ms.custom: sfi-ropc-nochange
2525

2626
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
2727

28-
In order to create a user-defined type (UDT) on the client, the assembly that was registered as a UDT in a [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] database must be available to the client application. The UDT assembly can be placed in the same directory with the application, or in the Global Assembly Cache (GAC). You can also set a reference to the assembly in your project.
28+
To create a user-defined type (UDT) on the client, the assembly registered as a UDT in a [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] database must be available to the client application. The UDT assembly can be placed in the same directory with the application, or in the Global Assembly Cache (GAC). You can also set a reference to the assembly in your project.
2929

3030
## Requirements for using UDTs in ADO.NET
3131

32-
The assembly loaded in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] and the assembly on the client must be compatible in order for the UDT to be created on the client. For UDTs defined with the `Native` serialization format, the assemblies must be structurally compatible. For assemblies defined with the `UserDefined` format, the assembly must be available on the client.
32+
The assembly loaded in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] and the assembly on the client must be compatible for the UDT to be created on the client. For UDTs defined with the `Native` serialization format, the assemblies must be structurally compatible. For assemblies defined with the `UserDefined` format, the assembly must be available on the client.
3333

34-
You don't need a copy of the UDT assembly on the client in order to retrieve the raw data from a UDT column in a table.
34+
You don't need a copy of the UDT assembly on the client to retrieve the raw data from a UDT column in a table.
3535

3636
> [!NOTE]
37-
> `SqlClient` might fail to load a UDT in the event of mismatched UDT versions or other problems. In this case, use regular troubleshooting mechanisms to determine why the assembly containing the UDT can't be found by the calling application. For more information, see [Diagnose Errors with Managed Debugging Assistants](/dotnet/framework/debug-trace-profile/diagnosing-errors-with-managed-debugging-assistants).
37+
> `SqlClient` might fail to load a UDT if UDT versions are mismatched or other problems occur. In this case, use regular troubleshooting mechanisms to determine why the assembly containing the UDT can't be found by the calling application. For more information, see [Diagnose Errors with Managed Debugging Assistants](/dotnet/framework/debug-trace-profile/diagnosing-errors-with-managed-debugging-assistants).
38+
39+
The code examples in this article use `Microsoft.Data.SqlClient`, which is available as a NuGet package. To add this dependency to your project, run the following command:
40+
41+
```dotnetcli
42+
dotnet add package Microsoft.Data.SqlClient
43+
```
3844

3945
## Access UDTs with a SqlDataReader
4046

41-
A `System.Data.SqlClient.SqlDataReader` can be used from client code to retrieve a result set that contains a UDT column, which is exposed as an instance of the object.
47+
Use a `Microsoft.Data.SqlClient.SqlDataReader` from client code to retrieve a result set that contains a UDT column, which is exposed as an instance of the object.
4248

4349
### Example
4450

@@ -50,11 +56,11 @@ This example shows how to use the `Main` method to create a new `SqlDataReader`
5056

5157
1. The UDT defines a `Distance` method and a `GetDistanceFromXY` method.
5258

53-
1. The sample code retrieves the values of the primary key and UDT columns in order to demonstrate the capabilities of the UDT.
59+
1. The sample code retrieves the values of the primary key and UDT columns to demonstrate the capabilities of the UDT.
5460

5561
1. The sample code calls the `Point.Distance` and `Point.GetDistanceFromXY` methods.
5662

57-
1. The results are displayed in the console window.
63+
1. The results display in the console window.
5864

5965
> [!NOTE]
6066
> The application must already have a reference to the UDT assembly.
@@ -63,8 +69,7 @@ This example shows how to use the `Main` method to create a new `SqlDataReader`
6369

6470
```csharp
6571
using System;
66-
using System.Data.Sql;
67-
using System.Data.SqlClient;
72+
using Microsoft.Data.SqlClient;
6873

6974
namespace Microsoft.Samples.SqlServer
7075
{
@@ -118,8 +123,7 @@ Option Explicit On
118123
Option Strict On
119124

120125
Imports System
121-
Imports System.Data.Sql
122-
Imports System.Data.SqlClient
126+
Imports Microsoft.Data.SqlClient
123127

124128
Module ReadPoints
125129
Sub Main()
@@ -164,18 +168,17 @@ End Module
164168

165169
## Bind UDTs as bytes
166170

167-
In some situations, you might want to retrieve the raw data from the UDT column. Perhaps the type isn't available locally, or you don't wish to instantiate an instance of the UDT. You can read the raw bytes into a byte array using the `GetBytes` method of a `SqlDataReader`. This method reads a stream of bytes from the specified column offset into the buffer of an array starting at a specified buffer offset. Another option is to use one of the `GetSqlBytes` or `GetSqlBinary` methods and read all of the contents in a single operation. In either case, the UDT object is never instantiated, so you don't need to set a reference to the UDT in the client assembly.
171+
In some situations, you might want to retrieve the raw data from the UDT column. Perhaps the type isn't available locally, or you don't want to instantiate an instance of the UDT. You can read the raw bytes into a byte array by using the `GetBytes` method of a `SqlDataReader`. This method reads a stream of bytes from the specified column offset into the buffer of an array starting at a specified buffer offset. Another option is to use one of the `GetSqlBytes` or `GetSqlBinary` methods and read all of the contents in a single operation. In either case, the UDT object is never instantiated, so you don't need to set a reference to the UDT in the client assembly.
168172

169173
### Example
170174

171-
This example shows how to retrieve the `Point` data as raw bytes into a byte array using a `SqlDataReader`. The code uses a `System.Text.StringBuilder` to convert the raw bytes to a string representation to be displayed in the console window.
175+
This example shows how to retrieve the `Point` data as raw bytes into a byte array by using a `SqlDataReader`. The code uses a `System.Text.StringBuilder` to convert the raw bytes to a string representation to be displayed in the console window.
172176

173177
### [C#](#tab/csharp)
174178

175179
```csharp
176180
using System;
177-
using System.Data.Sql;
178-
using System.Data.SqlClient;
181+
using Microsoft.Data.SqlClient;
179182
using System.Data.SqlTypes;
180183
using System.Text;
181184

@@ -228,8 +231,7 @@ Option Explicit On
228231
Option Strict On
229232

230233
Imports System
231-
Imports System.Data.Sql
232-
Imports System.Data.SqlClient
234+
Imports Microsoft.Data.SqlClient
233235
Imports System.Data.SqlTypes
234236
Imports System.Text
235237

@@ -281,14 +283,13 @@ End Module
281283

282284
### Example using GetSqlBytes
283285

284-
This example shows how to retrieve the `Point` data as raw bytes in a single operation using the `GetSqlBytes` method. The code uses a `StringBuilder` to convert the raw bytes to a string representation to be displayed in the console window.
286+
This example shows how to retrieve the `Point` data as raw bytes in a single operation by using the `GetSqlBytes` method. The code uses a `StringBuilder` to convert the raw bytes to a string representation to be displayed in the console window.
285287

286288
### [C#](#tab/csharp)
287289

288290
```csharp
289291
using System;
290-
using System.Data.Sql;
291-
using System.Data.SqlClient;
292+
using Microsoft.Data.SqlClient;
292293
using System.Data.SqlTypes;
293294
using System.Text;
294295

@@ -342,8 +343,7 @@ Option Explicit On
342343
Option Strict On
343344

344345
Imports System
345-
Imports System.Data.Sql
346-
Imports System.Data.SqlClient
346+
Imports Microsoft.Data.SqlClient
347347
Imports System.Data.SqlTypes
348348
Imports System.Text
349349

@@ -393,11 +393,11 @@ End Module
393393

394394
## Work with UDT parameters
395395

396-
UDTs can be used as both input and output parameters in your ADO.NET code.
396+
You can use UDTs as both input and output parameters in your ADO.NET code.
397397

398398
## Use UDTs in query parameters
399399

400-
UDTs can be used as parameter values when setting up a `SqlParameter` for a `System.Data.SqlClient.SqlCommand` object. The `SqlDbType.Udt` enumeration of a `SqlParameter` object is used to indicate that the parameter is a UDT when calling the `Add` method to the `Parameters` collection. The `UdtTypeName` property of a `SqlCommand` object is used to specify the fully qualified name of the UDT in the database using the `<database>.<schema_name>.<object_name>` syntax. You should use the fully qualified name to avoid ambiguity in your code.
400+
You can use UDTs as parameter values when you set up a `SqlParameter` for a `Microsoft.Data.SqlClient.SqlCommand` object. The `SqlDbType.Udt` enumeration of a `SqlParameter` object indicates that the parameter is a UDT when calling the `Add` method to the `Parameters` collection. The `UdtTypeName` property of a `SqlCommand` object specifies the fully qualified name of the UDT in the database by using the `<database>.<schema_name>.<object_name>` syntax. Use the fully qualified name to avoid ambiguity in your code.
401401

402402
A local copy of the UDT assembly must be available to the client project.
403403

@@ -410,8 +410,7 @@ The code in this example creates `SqlCommand` and `SqlParameter` objects to inse
410410
```csharp
411411
using System;
412412
using System.Data;
413-
using System.Data.Sql;
414-
using System.Data.SqlClient;
413+
using Microsoft.Data.SqlClient;
415414

416415
class Class1
417416
{
@@ -449,9 +448,8 @@ Option Explicit On
449448
Option Strict On
450449

451450
Imports System
452-
Imports system.Data
453-
Imports System.Data.Sql
454-
Imports System.Data.SqlClient
451+
Imports System.Data
452+
Imports Microsoft.Data.SqlClient
455453

456454
Module Module1
457455

docs/relational-databases/clr-integration-database-objects-user-defined-types/accessing-user-defined-types-updating-udt-columns-with-dataadapters.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: "Updating UDT Columns With DataAdapters"
3-
description: UDTs in a SQL Server database are supported by using System.Data.DataSet and System.Data.SqlClient.SqlDataAdapter to retrieve and modify data.
3+
description: UDTs in a SQL Server database are supported by using System.Data.DataSet and Microsoft.Data.SqlClient.SqlDataAdapter to retrieve and modify data.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: 12/27/2024
6+
ms.date: 03/19/2026
77
ms.service: sql
88
ms.subservice: clr
99
ms.topic: "reference"
@@ -26,11 +26,17 @@ ms.custom: sfi-ropc-nochange
2626

2727
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
2828

29-
User-defined types (UDTs) are supported by using a `System.Data.DataSet` and a `System.Data.SqlClient.SqlDataAdapter` to retrieve and modify data.
29+
You can retrieve and modify user-defined types (UDTs) by using a `System.Data.DataSet` and a `Microsoft.Data.SqlClient.SqlDataAdapter`.
30+
31+
The code examples in this article use `Microsoft.Data.SqlClient`, which is available as a NuGet package. To add this dependency to your project, run the following command:
32+
33+
```dotnetcli
34+
dotnet add package Microsoft.Data.SqlClient
35+
```
3036

3137
## Populate a dataset
3238

33-
You can use a [!INCLUDE [tsql](../../includes/tsql-md.md)] `SELECT` statement to select UDT column values to populate a dataset using a data adapter. The following example assumes that you have a `Points` table defined with the following structure and some sample data. The following [!INCLUDE [tsql](../../includes/tsql-md.md)] statements create the `Points` table and insert a few rows.
39+
Use a [!INCLUDE [tsql](../../includes/tsql-md.md)] `SELECT` statement to select UDT column values to populate a dataset by using a data adapter. The following example assumes that you have a `Points` table defined with the following structure and some sample data. The following [!INCLUDE [tsql](../../includes/tsql-md.md)] statements create the `Points` table and insert a few rows.
3440

3541
```sql
3642
CREATE TABLE dbo.Points
@@ -81,7 +87,7 @@ You can use two methods to update a UDT column in a `DataSet`:
8187

8288
- Provide custom `InsertCommand`, `UpdateCommand`, and `DeleteCommand` objects for a `SqlDataAdapter` object.
8389

84-
- Use the command builder (`System.Data.SqlClient.SqlCommandBuilder`) to create automatically the `INSERT`, `UPDATE`, and `DELETE` commands for you. In order to have conflict detection, add a **timestamp** column (alias **rowversion**) to the [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] table that contains the UDT. The **timestamp** data type allows you to version-stamp the rows in a table, and is guaranteed to be unique within a database. When a value in the table is changed, [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] automatically updates the 8-byte binary number for the row affected by the change.
90+
- Use the command builder (`Microsoft.Data.SqlClient.SqlCommandBuilder`) to create automatically the `INSERT`, `UPDATE`, and `DELETE` commands for you. To enable conflict detection, add a **timestamp** column (alias **rowversion**) to the [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] table that contains the UDT. The **timestamp** data type allows you to version-stamp the rows in a table, and is guaranteed to be unique within a database. When a value in the table is changed, [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] automatically updates the 8-byte binary number for the row affected by the change.
8591

8692
The `SqlCommandBuilder` doesn't consider the UDT for conflict detection unless there's a **timestamp** column in the underlying table. UDTs might or might not be comparable, so they aren't included in the `WHERE` clause when the "compare original values" option is used to generate a command.
8793

@@ -112,7 +118,7 @@ VALUES (4, CONVERT (Point, '4,6'));
112118

113119
The following ADO.NET example has two methods:
114120

115-
- `UserProvidedCommands`, which demonstrates how to supply `InsertCommand`, `UpdateCommand`, and `DeleteCommand` objects for updating the `Point` UDT in the `Points` table (which doesn't contain a **timestamp** column).
121+
- `UserProvidedCommands`, which demonstrates how to supply `InsertCommand`, `UpdateCommand`, and `DeleteCommand` objects for updating the `Point` UDT in the `Points` table (without a **timestamp** column).
116122

117123
- `CommandBuilder`, which demonstrates how to use a `SqlCommandBuilder` in the `Points_ts` table that contains the **timestamp** column.
118124

@@ -121,7 +127,7 @@ The following ADO.NET example has two methods:
121127
```csharp
122128
using System;
123129
using System.Data;
124-
using System.Data.SqlClient;
130+
using Microsoft.Data.SqlClient;
125131

126132
class Class1
127133
{
@@ -268,7 +274,7 @@ class Class1
268274
```vb
269275
Imports System
270276
Imports System.Data
271-
Imports System.Data.SqlClient
277+
Imports Microsoft.Data.SqlClient
272278

273279
Module Module1
274280
' Retrieves the connection string

0 commit comments

Comments
 (0)