Export (0) Print
Expand All

Readme_Large_UDT_OLEDB

New: 23 January 2009

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 (OLE DB) in SQL Server Books Online.

This sample uses Visual C++.

Before running this sample, make sure the following software is installed:

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]
    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
    
    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.
  3. Build the C++ project (FetchRowsWithLargeUDTTypes).

  • From Visual Studio, invoke Start Without Debugging (CTRL+F5) on the C++ project.
  • If you built with MSBuild.exe, invoke FetchRowsWithLargeUDTTypes.exe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft