2/12/2008 9:30:29 PM
[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 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.
Scenario
For more information about the enhanced support for date/time features, see Date/Time Improvements [OLE DB] in Books Online.
Languages
This sample uses Transact-SQL and Visual C++.
Prerequisites
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 theMicrosoft Download Center .
-
The AdventureWorks database, which is included with SQL Server and is also available from the
Microsoft SQL Server Developer Center .
-
The SQL Server Database Engine samples. These samples are included with SQL Server. You can download the latest version of the samples 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 SDK.
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 fromL"localhost"
toL"localhost\\name"
, wherename
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:
In SQL Server Management Studio, load and execute the Scripts\setup.sql script or execute the following command in a Command Prompt window:CREATE PROCEDURE sp_datetimetypes @date_param DATE OUTPUT, @time_param TIME(7) OUTPUT, @datetime2_param DATETIME2(7) OUTPUT, @datetimeoffset_param DATETIMEOFFSET(7) OUTPUT AS SELECT @date_param, @time_param, @datetime2_param, @datetimeoffset_param GO
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.