--- title: "Large UDTs" description: "Demonstrates how to retrieve data from large value UDTs introduced in SQL Server 2008." ms.date: "08/15/2019" dev_langs: - "csharp" ms.assetid: 420ae24e-762b-4e09-b4c3-2112c470ee49 ms.prod: sql ms.prod_service: connectivity ms.technology: connectivity ms.topic: conceptual author: David-Engel ms.author: v-daenge ms.reviewer: v-kaywon --- # Large UDTs [!INCLUDE[Driver_ADONET_Download](../../../includes/driver_adonet_download.md)] User-defined types (UDTs) allow a developer to extend the server's scalar type system by storing common language runtime (CLR) objects in a SQL Server database. UDTs can contain multiple elements and can have behaviors, unlike the traditional alias data types, which consist of a single SQL Server system data type. Previously, UDTs were restricted to a maximum size of 8 kilobytes. In SQL Server 2008, this restriction has been removed for UDTs that have a format of . For the complete documentation for user-defined types, see [CLR User-Defined Types](https://go.microsoft.com/fwlink/?LinkId=98366) from SQL Server Books Online. ## Retrieving UDT schemas using GetSchema The method of returns database schema information in a . ### GetSchemaTable column values for UDTs The method of a returns a that describes column metadata. The following table describes the differences in the column metadata for large UDTs between SQL Server 2005 and SQL Server 2008. |SqlDataReader column|SQL Server 2005|SQL Server 2008 and later| |--------------------------|---------------------|-------------------------------| |`ColumnSize`|Varies|Varies| |`NumericPrecision`|255|255| |`NumericScale`|255|255| |`DataType`|`Byte[]`|UDT instance| |`ProviderSpecificDataType`|`SqlTypes.SqlBinary`|UDT instance| |`ProviderType`|21 (`SqlDbType.VarBinary`)|29 (`SqlDbType.Udt`)| |`NonVersionedProviderType`|29 (`SqlDbType.Udt`)|29 (`SqlDbType.Udt`)| |`DataTypeName`|`SqlDbType.VarBinary`|The three part name specified as *Database.SchemaName.TypeName*.| |`IsLong`|Varies|Varies| ## SqlDataReader considerations The has been extended beginning in SQL Server 2008 to support retrieving large UDT values. How large UDT values are processed by a depends on the version of SQL Server you are using, as well as on the `Type System Version` specified in the connection string. For more information, see . The following methods of will return a instead of a UDT when the `Type System Version` is set to SQL Server 2005: - - - - - The following methods will return an array of `Byte[]` instead of a UDT when the `Type System Version` is set to SQL Server 2005: - - Note that no conversions are made for the current version of ADO.NET. ## Specifying SqlParameters The following properties have been extended to work with large UDTs. |SqlParameter Property|Description| |---------------------------|-----------------| ||Gets or sets an object that represents the value of the parameter. The default is null. The property can be `SqlBinary`, `Byte[]`, or a managed object.| ||Gets or sets an object that represents the value of the parameter. The default is null. The property can be `SqlBinary`, `Byte[]`, or a managed object.| ||Gets or sets the size of the parameter value to resolve. The default value is 0. The property can be an integer that represents the size of the parameter value. For large UDTs, it can be the actual size of the UDT, or -1 for unknown.| ## Retrieving data example The following code fragment demonstrates how to retrieve large UDT data. The `connectionString` variable assumes a valid connection to a SQL Server database and the `commandString` variable assumes a valid SELECT statement with the primary key column listed first. ```csharp using (SqlConnection connection = new SqlConnection( connectionString, commandString)) { connection.Open(); SqlCommand command = new SqlCommand(commandString); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { // Retrieve the value of the Primary Key column. int id = reader.GetInt32(0); // Retrieve the value of the UDT. LargeUDT udt = (LargeUDT)reader[1]; // You can also use GetSqlValue and GetValue. // LargeUDT udt = (LargeUDT)reader.GetSqlValue(1); // LargeUDT udt = (LargeUDT)reader.GetValue(1); Console.WriteLine( "ID={0} LargeUDT={1}", id, udt); } reader.close } ``` ## Next steps - [SQL Server binary and large-value data](sql-server-binary-large-value-data.md)