The UDTUtilities sample contains a number of utility functions. They include functions to expose assembly metadata to Transact-SQL, sample streaming table-valued functions (TVFs) to return the types in an assembly as a table, and functions to return the fields, methods, and properties in a user-defined data type. Technologies that are demonstrated include streaming TVFs, .NET Framework reflection APIs, and invocation of TVFs from Transact-SQL.

When you compile common language runtime integration samples, note that the path of the version of the compiler that was distributed with SQL Server 2005 must be the first Framework directory in the PATH environment variable. The location of the compiler that is included with SQL Server 2005 is either drive:\WINNT\Microsoft.NET\Framework\v2.0.xxxxx or drive:\Windows\Microsoft.NET\Framework\v2.0.xxxxx, where drive is the installation drive and xxxxx is the .NET Framework version that is included with your copy of SQL Server 2005.

The default installation directory is drive:\Program Files\Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\UDTUtilities

Scenario

A developer would like to access metadata about CLR-based user-defined data types.

Languages

Transact-SQL, Visual C#, and Visual Basic.

Features

The UDTUtilities sample uses the following SQL Server 2005 features:

Application Area Features

Overall

CLR

Prerequisites

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

  • SQL Server 2005 or SQL Server 2005 Express Edition (SQL Server Express). You can obtain SQL Server Express free of charge from the SQL Server 2005 Express Edition Documentation and Samples Web site.

  • The AdventureWorks database, which ships with SQL Server 2005, and also is available at the SQL Server 2005 Express Edition Documentation and Samples Web site.

  • The SQL Server 2005 Database Engine samples. These samples ship with SQL Server 2005, and also ship with the Microsoft Microsoft .NET Framework version 2.0 SDK 2.0.

  • .NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain .NET Framework SDK free of charge. See Installing the .NET Framework SDK.

Building the Sample

To build the sample, do the following:

Build the sample

  1. CD to the install directory and execute the following at a .NET Framework or Microsoft Visual Studio 2005 command prompt:

    sn -k temp.snk

  2. Compile the sample by using Visual Studio 2005 and the provided Visual Studio solution, or by using , which is included in the .NET Framework SDK 2.0, by executing a command similar to the following at the command prompt:

    msbuild /nologo /verbosity:quiet /property:Configuration=Debug CS\UDTUtilities.sln

  3. Ensure that the AdventureWorks database is installed, or, if necessary, create the database in which you want to install the samples.

  4. Open the scripts\installCS.sql or scripts\installVB.sql file, depending on whether you compiled the Visual C# project or the Visual Basic project, in SQL Server Management Studio. Execute the script that is contained in the file, or execute a command similar to the following at the command prompt:

    sqlcmd -E -I -i Scripts\InstallCS.sql

    This file contains script to install and register the utility samples in SQL Server.

Running the Sample

To run the sample, do the following:

Run the sample

  1. Open the scripts\test.sql file in SQL Server Management Studio and execute the script that is contained in the file, or execute the following command at the command prompt:

    sqlcmd -E -I -i Scripts\test.sql

    This script invokes the sample utility sample objects from Transact-SQL.

Removing the Sample

To remove the sample, do the following:

Remove the sample

  1. Open the scripts\cleanup.sql file in SQL Server Management Studio and execute the script contained in the file, or execute the following command at the command prompt:

    sqlcmd -E -I -i Scripts\cleanup.sql

    This script removes the sample.

Comments

The CLR for SQL Server 2005 or SQL Server Express must be enabled for this sample to work correctly.

Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. Sample applications and assemblies should not be connected to or used with your production SQL Server database or your report server without the permission of the system administrator.