Readme for Spatial Storage

February 13, 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 inserts two rows into a table with a geography column from a WellKnownBinary (WKB) using 2 different bindings (SQLCCHAR and SQLCBINARY). Then it selects one row from that table and uses ::STAsText() to display it.
The WKB is 0x01010000000700ECFAD03A4C4001008000B5DF07C0 and the application prints to the console: POINT(56.4595 -2.9842).
This sample does not require an ODBC data source, but the sample runs, by default, on the local instance of SQL Server.
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.

Scenario

For more information about spatial storage, see Designing and Implementing Spatial Storage in SQL Server Books Online.

Languages

This sample uses Visual C++.

Prerequisites

Before running this sample, make sure that the following software is installed:
  • SQL Server or SQL Server Express, including 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.
  • .NET Framework SDK 2.0 (or later) or Microsoft Visual Studio 2005 (or later). You can obtain .NET Framework SDK free of charge. For more information, see Installing the .NET Framework Documentation.
  • The source code for this sample. Click on the Releases tab above then click on either the appropriate installer for the computer you are using or click on the zip file for any machine architecture.

Building the Sample

  • This sample connects to your computer's default SQL Server instance. To connect to a non-default instance, change the Server attribute in odbc_spatial.cpp.
  • The sample requires you to execute the following Transact-SQL statements, which you can find in the sample's scripts directory
    USE tempdb
    GO
    
    IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SpatialSample')
       DROP TABLE SpatialSample
    
    CREATE TABLE SpatialSample (Name varchar(10), Geog Geography)
    GO 
    
    • In SQL Server Management Studio, load and execute the Scripts\setup.sql script or execute the following command in a Command Prompt window:
    sqlcmd -E -I -i Scripts\setup.sql
    • If you are using Visual Studio, load the odbc_spatial.sln file and build it.
    • If you are using MSBuild.exe, invoke MSBuild.exe at a command prompt, passing it the odbc_spatial.sln file:
    MSBuild odbc_spatial.sln

    Running the Sample

    • From Visual Studio, invoke Start Without Debugging (CTRL+F5).
    • If you built with MSBuild.exe, invoke odbc_spatial.exe. The sample outputs the following: POINT(56.4595 -2.9842).

    See Also

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

Last edited Feb 14, 2009 at 1:24 AM by bonniefe, version 7

Comments

No comments yet.