Share via


Readme_Spatial_Storage

[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 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 (SQL_C_CHAR and SQL_C_BINARY). 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:

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 R2 Assistance