This project is read-only.

Readme_Enhanced Date/Time Features Sample (OLE DB)

11/05/2008 21:36:06

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 shows how to use the date/time features that were introduced in SQL Server 2008 with OLE DB. The sample uses the four new date and time types (date, time, datetim2, and datetimeoffset) to execute commands with parameters and retrieve rowset results.
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.


For more information about the enhanced support for date/time features, see Date/Time Improvements (OLE DB) in Books Online.


This sample uses Transact-SQL and Visual C++.


Before running this sample, make sure 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 AdventureWorks database, that is available from the Microsoft SQL Server Developer Center.
  • The SQL Server Database Engine samples that are available at the Microsoft SQL Server Developer Center. This sample will use the AdventureWorks database.
  • .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.

Building the Sample

  • This sample connects to your computer's default SQL Server instance. Note that on some Windows operating systems, you will have to change localhost to the name of your SQL Server instance. To connect to a named instance, change the connection string from L"localhost" to L"localhost\\name" , where name is the named instance. By default, SQL Server Express installs to a named instance.
  • Make sure your INCLUDE environment variable includes the directory that contains sqlncli.h.
  • The sample requires you to execute the following stored procedure, which you can find in the sample's scripts directory: * CREATE PROCEDURE sp_datetimetypes
    @date_param DATE OUTPUT,
    @time_param TIME(7) OUTPUT,
    @datetime2_param DATETIME2(7) OUTPUT,
    @datetimeoffset_param DATETIMEOFFSET(7) OUTPUT
    SELECT @date_param, @time_param, @datetime2_param, @datetimeoffset_param
    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 datetimeoledb.sln file and build it.
    • If you are using MSBuild.exe, invoke MSBuild.exe at a command prompt, passing it the datetimeoledb.sln file: * MSBuild datetimeoledb.sln *

    Running the Sample

    • From Visual Studio, invoke Start Without Debugging (CTRL+F5).
    • If you built with MSBuild.exe, invoke datetimeoledb.exe.

    See Also

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

Last edited Nov 6, 2008 at 10:47 PM by bonniefe, version 3


No comments yet.