This project is read-only.


11/05/2008 21:36:06

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.


This sample uses Visual C++.


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.

Building the Sample

Build this sample as follows:
  1. 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.
  2. Run the following Transact-SQL script: * USE [MASTER]

    FROM 'C:\LargeStringUDT.dll'

    CREATE TYPE dbo.LargeStringUDT
    EXTERNAL NAME LargeStringUDT.[LargeStringUDT];

    CREATE TABLE dbo.LargeStringUDTs
    (ID int IDENTITY(1,1) PRIMARY KEY, LargeString LargeStringUDT)

    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 * This script references the DLL created by the C# project. So, if you modified the post-build event to change the directory location of the DLL, also modify this script.
    1. Build the C++ project (FetchRowsWithLargeUDTTypes).

    Running the Sample

    • From Visual Studio, invoke Start Without Debugging (CTRLF5) on the C+ project.
    • If you built with MSBuild.exe, invoke FetchRowsWithLargeUDTTypes.exe.

    See Also

    Data Access Samples
    Help and Information
    • Getting SQL Server 2008 Assistance* © 2008 Microsoft Corporation. All rights reserved.

Last edited Nov 6, 2008 at 11:03 PM by bonniefe, version 1


No comments yet.