Skip to content

Commit df4580e

Browse files
Documentation for JSON and Vector datatype support in SqlClient (#35789)
* Commit initial draft for JSON and Vector documentation * Fetch samples from sqlclient repo * Remove hardcoded links * Update docs/connect/ado-net/configure-parameters.md Co-authored-by: David Engel <dengel1012@gmail.com> * Update docs/connect/ado-net/sql/vector-data-sql-server.md Co-authored-by: David Engel <dengel1012@gmail.com> * Update docs/connect/ado-net/configure-parameters.md Co-authored-by: David Engel <dengel1012@gmail.com> * Update docs/connect/ado-net/sql/json-data-sql-server.md Co-authored-by: David Engel <dengel1012@gmail.com> * Address review comments * Acrolinx improvements Applied Acrolinx suggestions to increase the score above 80. * Apply fix suggestions * Escape back tick --------- Co-authored-by: Apoorv Deshmukh <apdeshmukh@microsoft.com>
1 parent ad910af commit df4580e

File tree

6 files changed

+123
-23
lines changed

6 files changed

+123
-23
lines changed

docs/connect/ado-net/configure-parameters.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,22 @@ The Microsoft SqlClient Data Provider for SQL Server type of a `Parameter` objec
7272
||`StringFixedLength`|`NChar`|
7373
||`Time`|`Time` in SQL Server 2008. Inferring a <xref:System.Data.SqlDbType> from `Time` isn't supported in versions of SQL Server earlier than SQL Server 2008.|
7474
||`VarNumeric`|Inferring a <xref:System.Data.SqlDbType> from `VarNumeric` isn't supported.|
75-
|user-defined type (an object with <xref:Microsoft.SqlServer.Server.SqlUserDefinedAggregateAttribute>|SqlClient always returns an Object|`SqlDbType.Udt` if <xref:Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute> is present, otherwise `Variant`|
75+
|user-defined type (an object with <xref:Microsoft.SqlServer.Server.SqlUserDefinedAggregateAttribute>)|SqlClient always returns an Object|`SqlDbType.Udt` if <xref:Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute> is present, otherwise `Variant`|
76+
|<xref:Microsoft.Data.SqlTypes.SqlJson>|`String`|`SqlDbType.Json`|
77+
|<xref:Microsoft.Data.SqlTypes.SqlVector%601>|`Binary`|`SqlDbType.Vector`|
7678

7779
> [!NOTE]
7880
> Conversions from decimal to other types are narrowing conversions that round the decimal value to the nearest integer value toward zero. If the result of the conversion isn't representable in the destination type, an <xref:System.OverflowException> is thrown.
7981
82+
> [!NOTE]
83+
> **JSON**
84+
>
85+
> Set SqlDbType to Json when passing a parameter `Value` of type `string`. Otherwise SqlDbType defaults to `Nvarchar`.
86+
>
87+
> **Vector**
88+
>
89+
> For SQL vector datatype, a parameter `Value` of type `Microsoft.Data.SqlTypes.SqlVector<T>` must be specified. Parameter `Size` and vector dimension are inferred from the parameter `Value`. The parameter `Size` is ignored.
90+
8091
> [!NOTE]
8192
> When you send a null parameter value to the server, you must specify <xref:System.DBNull>, not `null` (`Nothing` in Visual Basic). The null value in the system is an empty object that has no value. <xref:System.DBNull> is used to represent null values.
8293

docs/connect/ado-net/sql-server-data-type-mappings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ The following table shows the inferred .NET Framework type, the <xref:System.Dat
5353
|varbinary|Byte[]|<xref:System.Data.SqlDbType.VarBinary>|<xref:Microsoft.Data.SqlClient.SqlDataReader.GetSqlBinary%2A>|<xref:System.Data.DbType.Binary>|<xref:Microsoft.Data.SqlClient.SqlDataReader.GetBytes%2A>|
5454
|varchar|String<br /><br /> Char[]|<xref:System.Data.SqlDbType.VarChar>|<xref:Microsoft.Data.SqlClient.SqlDataReader.GetSqlString%2A>|<xref:System.Data.DbType.AnsiString>, <xref:System.Data.DbType.String>|<xref:Microsoft.Data.SqlClient.SqlDataReader.GetString%2A><br /><br /> <xref:Microsoft.Data.SqlClient.SqlDataReader.GetChars%2A>|
5555
|xml|Xml|<xref:System.Data.SqlDbType.Xml>|<xref:Microsoft.Data.SqlClient.SqlDataReader.GetSqlXml%2A>|<xref:System.Data.DbType.Xml>|none|
56+
|json|String|<xref:System.Data.SqlDbType.Json>|<xref:Microsoft.Data.SqlClient.SqlDataReader.GetSqlJson%2A>|none|none|
57+
|vector|none|<xref:System.Data.SqlDbType.Vector>|<xref:Microsoft.Data.SqlClient.SqlDataReader.GetSqlVector%2A>|none|none|
5658

5759
<sup>1</sup> You cannot set the `DbType` property of a `SqlParameter` to `SqlDbType.Date`.
5860
<sup>2</sup> Use a specific typed accessor if you know the underlying type of the `sql_variant`.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: "JSON data type support in SqlClient"
3+
description: "Describes how to work with JSON data retrieved from SQL Server."
4+
author: apoorvdeshmukh
5+
ms.author: apdeshmukh
6+
ms.reviewer:
7+
ms.date: 10/31/2025
8+
ms.service: sql
9+
ms.subservice: connectivity
10+
ms.topic: conceptual
11+
---
12+
# JSON datatype support in SqlClient
13+
14+
[!INCLUDE[Driver_ADONET_Download](../../../includes/driver_adonet_download.md)]
15+
16+
A native [JSON data type](../../../t-sql/data-types/json-data-type.md) is introduced in SQL Server 2025 and Azure SQL databases. This native JSON data type is available for structured JSON documents with automatic validation, efficient transport, and efficient storage.
17+
18+
The Microsoft.Data.SqlClient provider offers built-in support for JSON columns through:
19+
- The common language runtime (CLR) `string` type for simple scenarios.
20+
- `SqlJson` type for advanced use cases, such as client-side validation and explicit handling of JSON semantics.
21+
- .NET 9 introduces a new SqlDbType.Json enumeration value for specifying JSON parameters. For earlier .NET versions, use `Microsoft.Data.SqlDbTypeExtensions`, which provides forward-compatible support for new SQL types.
22+
- .NET 9 introduces a new `SqlDbType.Json` enumeration value for specifying JSON parameters.
23+
- For earlier .NET versions, `Microsoft.Data.SqlDbTypeExtensions` is introduced as an alternative for `SqlDbType`.
24+
25+
## Example
26+
27+
The following example demonstrates the following scenarios to interact with JSON data.
28+
29+
- Insert a JSON value using CLR type `string`.
30+
- Insert the JSON value using `SqlJson`. Using `SqlJson` is useful if you want to validate the JSON data before sending it to server.
31+
- Insert a JSON file by streaming.
32+
- Read JSON values using `SqlDataReader`.
33+
- Use stored procedure parameters for JSON data.
34+
35+
[!code-csharp[SqlJsonExample#1](~/../sqlclient/doc/samples/SqlJsonExample.cs#1)]
36+
37+
## Next steps
38+
39+
- [SQL Server and ADO.NET](index.md)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Vector datatype support in SqlClient"
3+
description: "Describes how to work with vector datatype for SQL Server using SqlClient."
4+
author: apoorvdeshmukh
5+
ms.author: apdeshmukh
6+
ms.reviewer:
7+
ms.date: 10/31/2025
8+
ms.service: sql
9+
ms.subservice: connectivity
10+
ms.topic: conceptual
11+
---
12+
# Vector datatype support in SqlClient
13+
14+
[!INCLUDE[Driver_ADONET_Download](../../../includes/driver_adonet_download.md)]
15+
16+
SQL Server 2025 and Azure SQL Database introduce a native [Vector data type](../../../t-sql/data-types/vector-data-type.md) for storing fixed-dimension numeric embeddings with automatic validation and efficient binary storage. For backward compatibility, vectors are exposed as JSON arrays. Each element is float32 by default, and dimensions must range from 1 to 1998.
17+
18+
In .NET, the `Microsoft.Data.SqlClient` provider adds native vector handling through the <xref:Microsoft.Data.SqlTypes.SqlVector`1> class (for example, `SqlVector<float>`), using optimized binary transport over the Tabular Data Stream (TDS) protocol. Older clients can still pass vectors as JSON strings transparently.
19+
20+
The vector type enables similarity search and AI-driven scenarios, with server-side vector functions for efficient computation.
21+
22+
In SqlClient, `vector` data is exchanged with SQL Server using the <xref:Microsoft.Data.SqlTypes.SqlVector`1> class.
23+
24+
In newer .NET versions starting with version 10, a new `SqlDbType` enumeration value `Vector` is available for representing SQL parameters of type `vector`.
25+
26+
For earlier versions, use `Microsoft.Data.SqlDbTypeExtensions` to declare SQL parameters of type `vector`.
27+
28+
## Example
29+
30+
The following code sample demonstrates the following scenarios for a vector column of three dimensions.
31+
32+
- Insert non-null vectors using SqlParameter.
33+
- Insert null vectors for a given vector column.
34+
- Read a vector column.
35+
- Use a stored procedure with a vector datatype parameter.
36+
- Perform a bulk copy operation with vector data.
37+
38+
[!code-csharp[SqlVectorExample#1](~/../sqlclient/doc/samples/SqlVectorExample.cs#1)]
39+
40+
## Next steps
41+
42+
- [SQL Server and ADO.NET](index.md)

docs/connect/ado-net/sqlclient-streaming-support.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: "SqlClient streaming support"
3-
description: Discusses how to write applications that stream data from SQL Server without having it fully loaded in memory.
3+
description: Describes how to write applications that stream large data from SQL Server without loading it all in memory.
44
author: David-Engel
55
ms.author: davidengel
6-
ms.reviewer: v-chmalh
6+
ms.reviewer: cmalhotra
77
ms.date: "12/04/2020"
88
ms.service: sql
99
ms.subservice: connectivity
@@ -15,14 +15,14 @@ ms.topic: conceptual
1515

1616
[!INCLUDE[Driver_ADONET_Download](../../includes/driver_adonet_download.md)]
1717

18-
Streaming support between SQL Server and an application supports unstructured data on the server (documents, images, and media files). A SQL Server database can store binary large objects (BLOBs), but retrieving BLOBS can use a lot of memory.
18+
Streaming support between SQL Server and an application supports unstructured data on the server (documents, images, and media files). A SQL Server database can store binary large objects (BLOBs), but retrieving BLOBS can use a large amount of memory.
1919

2020
Streaming support to and from SQL Server simplifies writing applications that stream data, without having to fully load the data into memory, resulting in fewer memory overflow exceptions.
2121

22-
Streaming support will also enable middle-tier applications to scale better, especially in scenarios where business objects connect to Azure SQL in order to send, retrieve, and manipulate large BLOBs.
22+
Streaming support also enables middle-tier applications to scale better, especially in scenarios where business objects connect to Azure SQL in order to send, retrieve, and manipulate large BLOBs.
2323

2424
> [!WARNING]
25-
> The members that support streaming are used to retrieve data from queries and to pass parameters to queries and stored procedures. The streaming feature addresses basic OLTP and data migration scenarios and is applicable to on-premises and off-premises data migrations environments.
25+
> The members that support streaming are used to retrieve data from queries and to pass parameters to queries and stored procedures. The streaming feature addresses basic Online Transaction Processing (OLTP) and data migration scenarios and is applicable to on-premises and off-premises data migrations environments.
2626
2727
## Streaming support from SQL Server
2828

@@ -55,31 +55,33 @@ The following members were added to <xref:System.Data.Common.DbDataReader> to en
5555
Streaming support to SQL Server is in the <xref:Microsoft.Data.SqlClient.SqlParameter> class so it can accept and react to <xref:System.Xml.XmlReader>, <xref:System.IO.Stream>, and <xref:System.IO.TextReader> objects. <xref:Microsoft.Data.SqlClient.SqlParameter> is used to pass parameters to queries and stored procedures.
5656

5757
> [!NOTE]
58-
> Disposing a <xref:Microsoft.Data.SqlClient.SqlCommand> object or calling <xref:Microsoft.Data.SqlClient.SqlCommand.Cancel%2A> must cancel any streaming operation. If an application sends <xref:System.Threading.CancellationToken>, cancellation is not guaranteed.
58+
> Disposing a <xref:Microsoft.Data.SqlClient.SqlCommand> object or calling <xref:Microsoft.Data.SqlClient.SqlCommand.Cancel%2A> must cancel any streaming operation. If an application sends <xref:System.Threading.CancellationToken>, cancellation isn't guaranteed.
5959
60-
The following <xref:Microsoft.Data.SqlClient.SqlParameter.SqlDbType%2A> types will accept a <xref:Microsoft.Data.SqlClient.SqlParameter.Value%2A> of <xref:System.IO.Stream>:
60+
The following <xref:Microsoft.Data.SqlClient.SqlParameter.SqlDbType%2A> types accept a <xref:Microsoft.Data.SqlClient.SqlParameter.Value%2A> of <xref:System.IO.Stream>:
6161

62-
- **Binary**
62+
- `Binary`
6363

64-
- **VarBinary**
64+
- `VarBinary`
6565

66-
The following <xref:Microsoft.Data.SqlClient.SqlParameter.SqlDbType%2A> types will accept a <xref:Microsoft.Data.SqlClient.SqlParameter.Value%2A> of <xref:System.IO.TextReader>:
66+
The following <xref:Microsoft.Data.SqlClient.SqlParameter.SqlDbType%2A> types accept a <xref:Microsoft.Data.SqlClient.SqlParameter.Value%2A> of <xref:System.IO.TextReader>:
6767

68-
- **Char**
68+
- `Char`
6969

70-
- **NChar**
70+
- `NChar`
7171

72-
- **NVarChar**
72+
- `NVarChar`
7373

74-
- **Xml**
74+
- `Xml`
7575

76-
The **Xml**<xref:Microsoft.Data.SqlClient.SqlParameter.SqlDbType%2A> type will accept a <xref:Microsoft.Data.SqlClient.SqlParameter.Value%2A> of <xref:System.Xml.XmlReader>.
76+
- `Json`
77+
78+
The **Xml** <xref:Microsoft.Data.SqlClient.SqlParameter.SqlDbType%2A> type accepts a <xref:Microsoft.Data.SqlClient.SqlParameter.Value%2A> of <xref:System.Xml.XmlReader>.
7779

7880
<xref:Microsoft.Data.SqlClient.SqlParameter.SqlValue%2A> can accept values of type <xref:System.Xml.XmlReader>, <xref:System.IO.TextReader>, and <xref:System.IO.Stream>.
7981

80-
The <xref:System.Xml.XmlReader>, <xref:System.IO.TextReader>, and <xref:System.IO.Stream> object will be transferred up to the value defined by the <xref:Microsoft.Data.SqlClient.SqlParameter.Size%2A>.
82+
The <xref:System.Xml.XmlReader>, <xref:System.IO.TextReader>, and <xref:System.IO.Stream> object is transferred up to the value defined by the <xref:Microsoft.Data.SqlClient.SqlParameter.Size%2A>.
8183

82-
## Sample -- streaming from SQL Server
84+
## Sample--streaming from SQL Server
8385

8486
Use the following Transact-SQL to create the sample database:
8587

@@ -100,7 +102,7 @@ INSERT INTO [Streams] (textdata, bindata, xmldata) VALUES (N'Another row', 0x666
100102
GO
101103
```
102104

103-
The sample shows how to do the following:
105+
The sample shows how to do the following actions:
104106

105107
- Avoid blocking a user-interface thread by providing an asynchronous way to retrieve large files.
106108

@@ -114,7 +116,7 @@ The sample shows how to do the following:
114116

115117
[!code-csharp[SqlClient_Streaming_FromServer#1](~/../sqlclient/doc/samples/SqlClient_Streaming_FromServer.cs#1)]
116118

117-
## Sample -- streaming to SQL Server
119+
## Sample--streaming to SQL Server
118120

119121
Use the following Transact-SQL to create the sample database:
120122

@@ -137,23 +139,23 @@ CREATE TABLE [BinaryStreamsCopy] (
137139
GO
138140
```
139141

140-
The sample shows how to do the following:
142+
The sample shows how to do the following actions:
141143

142144
- Transferring a large BLOB to SQL Server in .NET.
143145

144146
- Transferring a large text file to SQL Server in .NET.
145147

146148
- Using the new asynchronous feature to transfer a large BLOB.
147149

148-
- Using the new asynchronous feature and the await keyword to transfer a large BLOB.
150+
- Using the new asynchronous feature and the `await` keyword to transfer a large BLOB.
149151

150152
- Cancelling the transfer of a large BLOB.
151153

152154
- Streaming from one SQL Server to another using the asynchronous feature.
153155

154156
[!code-csharp[SqlClient_Streaming_ToServer#1](~/../sqlclient/doc/samples/SqlClient_Streaming_ToServer.cs#1)]
155157

156-
## Sample -- Streaming from one SQL Server to another SQL Server
158+
## Sample--Streaming from one SQL Server to another SQL Server
157159

158160
This sample demonstrates how to asynchronously stream a large BLOB from one SQL Server to another, with support for cancellation.
159161

docs/connect/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@
210210
href: ../connect/ado-net/sql/sql-xml-column-values.md
211211
- name: Specifying XML values as parameters
212212
href: ../connect/ado-net/sql/specify-xml-values-parameters.md
213+
- name: JSON data type support in SqlClient
214+
href: ../connect/ado-net/sql/json-data-sql-server.md
215+
- name: Vector datatype support in SqlClient
216+
href: ../connect/ado-net/sql/vector-data-sql-server.md
213217
- name: SQL Server binary and large-value data
214218
href: ../connect/ado-net/sql/sql-server-binary-large-value-data.md
215219
items:

0 commit comments

Comments
 (0)