This project is read-only.

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:
  • SQL Server or SQL Server Express. You can obtain SQL Server Express free of charge from the SQL Server Express Documentation and Samples Web site.
  • The SQL Server Database Engine samples. These samples are included with SQL Server. You can download the latest version of the samples at the SQL Server Developer Web site.
  • .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

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
  • The first time to run the application, it will not have any models or "wireframes" in the database. You must load them from files. The "models" subdirectory contains several model files you can use.
  • Click File, click Open and select one of the models from the "models" subdirectory. The model will display in the screen, and you can use the X, Y and Z sliders to rotate the model. You can see the user-defined types being used in the client to represent triangle information and to perform the transformations in the Triangle.cs and Point3D.cs files in the db3dsql project.
Step 2: Connecting to a database
  • To connect to a database, click Database and then click Connect. A dialog box will pop up where you can enter the name of the server, the database and authentication information. You should specify db3d as the name of the database to use. Once you are done click OK to connect. You can see how to build a connection string that is based on user input in the see the connectToolStripMenuItem_Click method in the MainFrm.cs file in the db3dwin project.
  • If you want, you can use the server and the database combo-boxes to browse the available servers and databases. You can see how to obtain the list of servers and/or databases in the file ConnectDlg.cs in the db3dwin project.
  • NOTE: the list of servers will include only those servers in the network that are currently available and that have been specifically enabled for discoverability.
Step 3: Uploading a model to the database
  • Once connected, you can upload a model
  • With a model loaded from a file from step 1, and after you connect to the database as described in step 2, click Database and then click Copy wireframe. This will prompt for a name and upload the triangle information to the database. You can also decide whether to enable "fast upload" using bulk-copy. You can experiment with the difference between doing many inserts one by one and using SqlBulkCopy for it. See the WireframeDbStorage.cs file in the db3dlib project.
  • You can repeat this operation with several other models (or even several copies of the same one with different names), so that you have a database that has many models in it.
Step 4: Viewing more model information
  • The application has a second tab that lets you see a list of all the wireframes in the database. You can also see the number of triangles they are made of and the total surface of the model. The interesting thing about this is that the surface is computed in the server without having to ship the data to the client by using a user-defined aggregate. You can see the user-defined aggregate implementation in the surface.cs file in the db3dsql project. Also see step 6 for information about how to use it in Transact-SQL.
  • To see this information, click the Wireframe Information tab.
Step 5: Rotating a model using Transact-SQL
  • When

Last edited Jun 5, 2007 at 7:02 PM by bonniefe, version 5

Comments

No comments yet.