This sample works only with SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 2008.
This sample solution contains two projects. One project creates an assembly (DLL) from C# source code. This assembly contains the CLR type. A table will be added to the database. A column in the table will be of a type defined in the assembly, By default, this sample will use the master database. The second project is a native C++ application that reads data from the table.
SQL Server samples and sample databases must be downloaded and installed before you can view or work with them. For more information, see Considerations for Installing SQL Server Samples and Sample Databases.
For more information about large UDTs, see Large CLR User-Defined Types (ODBC) in SQL Server Books Online.
Before running this sample, make sure the following software is installed:
SQL Server or SQL Server Express, including the Database Engine.
You can download SQL Server Express from the Microsoft Download Center.
The SQL Server Database Engine samples that are available at the Microsoft SQL Server Developer Center.
The .NET Framework SDK 2.0 (or later) or Microsoft Visual Studio 2005 (or later). You can obtain the .NET Framework SDK free of charge. For more information, see Installing the .NET Framework Documentation.
Build this sample as follows:
Build the C# project (LargeStringUDT). This project creates a DLL. The project has a post-build event that copies the DLL to the root directory of your C:\ drive. If your C:\ drive is not available when you run this sample, modify the post-build event to use a different drive.
Run the following Transact-SQL script:
USE [MASTER] GO CREATE ASSEMBLY LargeStringUDT FROM 'C:\LargeStringUDT.dll' WITh PERMISSION_SET=SAFE; GO CREATE TYPE dbo.LargeStringUDT EXTERNAL NAME LargeStringUDT.[LargeStringUDT]; GO CREATE TABLE dbo.LargeStringUDTs (ID int IDENTITY(1,1) PRIMARY KEY, LargeString LargeStringUDT) GO INSERT INTO dbo.LargeStringUDTs (LargeString) VALUES (CONVERT(LargeStringUDT, 'This is the first string')); INSERT INTO dbo.LargeStringUDTs (LargeString) VALUES (CONVERT(LargeStringUDT, 'This is the second string')); INSERT INTO dbo.LargeStringUDTs (LargeString) VALUES (Convert(LargeStringUDT, 'This is the third string')); GO
Build the C++ project (FetchRowsWithLargeUDTTypes).