Including SQL-DMO

The first step to programming with SQL-DMO objects is to include the appropriate type library or header files in your project.

The complete SQL-DMO type library is contained in the SQLOLE32.TLB file, located in the C:\SQL60\DLL directory by default. The type library contains information about all SQL-DMO objects, properties and methods, and is usually used by OLE Automation controllers like Visual Basic.

Visual Basic

To give Visual Basic access to the SQL-DMO object definitions, you should include the SQL-DMO type library in your Visual Basic project or module. Including the type library is required if you want to declare a Visual Basic object variable as a SQL-DMO object type. Including the SQL-DMO type library is not necessary if you want to declare a Visual Basic object variable as a generic Object type.

To include the SQL-DMO type library in your project, you usually follow these steps. From the Tools menu, choose References. The References dialog appears. Choose the Browse button, and include the SQLOLE32.TLB file. This requires that the Visual Basic environment or module code editor be active and running. For example, to create a new Visual Basic module using Excel 5.0 for Windows NT, from the Insert menu, choose Macro and then Module.

C++

The SQL-DMO objects include both ANSI and Unicode custom interfaces. When using ANSI interfaces, all SQL-DMO strings are ANSI strings with one byte per character. When using the Unicode interfaces, all SQL-DMO strings are Unicode strings with two bytes per character. All SQL-DMO strings use the SQLOLE_BSTR string datatype.

The ANSI custom interfaces and ANSI SQLOLE_BSTR strings are used by default. If you want to use the Unicode custom interfaces and Unicode SQLOLE_BSTR strings, you must define UNICODE and _UNICODE before including all the header files. For example:

#define UNICODE
#define _UNICODE

Use the TEXT("str") macro around string values. By default these are ANSI "str" strings. When UNICODE and _UNICODE are defined these are Unicode L"str" strings.

In 32-bit OLE, all BSTR strings are Unicode strings.

To give your C++ program access to the SQL-DMO object definitions, you must include the SQLOLEID.H and SQLOLE.H header files, in addition to the Windows and OLE header files. The SQL-DMO header files are located in the C:\SQL60\SQLOLE\INCLUDE directory by default. The Include setting of the Visual C++ project or the INCLUDE environment variable should point to the directory that contains these files.

You must include the following header files in this order:

  1. WINDOWS.H
  2. INITGUID.H (This file must be included once and only once)
  3. SQLOLEID.H
  4. SQLOLE.H
#include <windows.h>
#include <initguid.h>
#include <sqloleid.h>
#include <sqlole.h>

SQL-DMO does not have a link library. However, to build your SQL-DMO application, you must link to the following OLE libraries:

The Library setting of the Visual C++ project or the LIB environment variable should point to the directory that contains these files.