Readme_DB3D

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This sample works only with SQL Server 2005 and SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 2005.
DB3D is an example application that stores, visualizes and manipulates tri-dimensional wireframe models by using SQL Server and .NET Framework.
The default installation directory is C:\Program Files\Microsoft SQL Server\100\Samples\Integrated Samples\DB3D

Scenario

The DB3D application illustrates how to take advantage of various SQL Server 2005 features to handle several common application needs.
The application can load tri-dimensional wireframe models from a file or from a database. It can also upload new wireframe models into a database by using various techniques that show different performance characteristics.
Wireframe models are represented by using triangles in space. Triangles are directly stored in the database as user-defined types and also used by the client application to manipulate the rendered wireframes.
Once in the database, wireframe models can be manipulated interactively on the client, or through Transact-SQL in the server by using the SQL-CLR methods included in the sample library. The application also supports reporting on the wireframes that are contained in the database, for which it uses custom aggregates to perform computation close to the data and avoids data-shipping costs.

Languages

Transact-SQL and Visual C#.

Features

The DB3D sample uses the new features of SQL Server as shown in the following table:

Application Area Features
Representing wireframe model data Use of SQL Server user-defined types to appropriately represent pieces of information of the problem domain of the application. In the case of DB3D, two user-defined types are defined, "Triangle" and "Point3D". The example shows how to use the types both from within SQL Server and from a client application through ADO.NET 2.0.
Manipulating wireframe models The "Triangle" and "Point3D" user-defined types include, in addition to their persistent state, a rich set of methods to manipulate them (for example to rotate a triangle in space). Those methods can be used both from the client and from within SQL Server itself to interact and change models.
Computing summary information for wireframe models Use of SQL Server user-defined aggregates to perform processing close to the data (in the database) using custom algorithms. The sample can compute the surface of a given model by using a custom aggregate. This lets the system perform the computation in an efficient environment (CLR) without having to ship the data to another tier.
Uploading wireframe data quickly into the database The application includes two strategies for uploading data: one based on regular INSERT statements and the other uses the new SqlBulkCopy class included in ADO.NET 2.0. Both are available so their performance characteristics can be compared.
Connect-to-database dialog box The new SqlConnectionStringBuilder class is used to construct a connection string that is based on user-input in a safe way, that helps protect the application from connection-string-injection attacks.
Connect-to-database dialog box The new SqlDataSourceEnumerator class is used to obtain the list of the instances of SQL Server that are available in the network.
Connect-to-database dialog box The new database schema access API is used to retrieve the list of available databases from a connection.


Prerequisites

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

Building the Sample

If you have not already created the strong-name key file SampleKey.snk generate the key file by using the following instructions.
To generate a strong name key file
  1. Open a Microsoft Visual Studio 2005 command prompt. Click Start, point to All Programs, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, and then click Visual Studio 2005 Command Prompt.—Or—Open a Microsoft .NET Framework command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.
  2. At the command prompt, use the change directory (CD) command to change the current folder of the Command Prompt window to the Samples folder. Note: To determine the folder where samples are located, click Start, point to All Programs, point to Microsoft SQL Server 2005, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <systemdrive_>:\Program Files\Microsoft SQL Server\90\Samples.
  3. At the command prompt, run the following command to generate the key file: sn -k SampleKey.snk ** Important: For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.To build the sample, do the following:
To build the sample
  1. Compile the sample by using Visual Studio 2005 and the provided Visual Studio solution or by using Microsoft MSBuild, which is included in the .NET Framework SDK 2.0. Run a command similar to the following at the command prompt: msbuild /nologo /verbosity:quiet /property:Configuration=Debug CS\db3d.sln
  2. If you did not install the SQL Server Database Engine samples in the default location, modify the path in the CREATE ASSEMBLY part of the script in Scripts\InstallCS.sql to refer to location where the samples were installed.
  3. If you are not an administrator for the SQL Server instance you are using, you must have an administrator grant you CreateAssembly permission to complete the installation.
  4. Open the scripts\installCS.sql in SQL Server Management Studio. Run the script that is contained in the file, or run a command similar to the following at the command prompt: sqlcmd -E -I -i Scripts\InstallCS.sql This script performs the following actions:
  5. Drops the old db3d database if it exists.
  6. Registers the db3dsql assembly.
  7. Registers some CLR UDTs and an aggregate.

Running the Sample

To run the sample, do the following:
Step 1: Loading models from files
Step 2: Connecting to a database
Step 3: Uploading a model to the database
Step 4: Viewing more model information
Step 5: Rotating a model using Transact-SQL