Omnis Technical Note TNSQ0015July 2007. Updated Sept 2023.

ODBC Administration with Omnis Studio

For Omnis Studio 4.3 and later
By Gary Ashford

Introduction

The ODBC DAM provides additional methods to enable administration of ODBC System, User and File data sources as well as ODBC drivers. These functions are normally performed by the ODBC Administrator utility under Windows and Mac OS X. This technote briefly describes how many of these functions can now be performed from an Omnis library.
An example library is also provided at the end of this page.

New Features

The following session methods have been added to the ODBC DAM.
Please refer to the online documentation for further details on session properties and methods that the ODBC DAM provides.

$getdrivers()

$getdrivers (lResult) retrieves a list of all ODBC drivers installed on the system. lResult is populated with the list of drivers installed and is defined with the following character columns:

  • DriverName - The alternate driver name (i.e. the descriptive name)
  • Version - The version string reported by the driver
  • CompanyName - The Company name embedded within the driver file (Windows only)
  • FileName - The physical path and file name of the driver

Example: Do tSess.$getdrivers(iDriverList) Returns #F

$getdatasources()

$getdatasources(lResult, kDSNMode) can be used to retrieve a list of ODBC System or User DSNs.
On return, lResult is defined with two character columns:

  • DSNName - The User assigned name for the data source
  • Driver - The alternate name of the driver associated with the data source

Example: Do tSess.$getdatasources(iDSNList,kODBCSystemDSN) Returns #F

$getinfo()

$getinfo(lResult, cDSNName, kDSNMode) retrieves the information defined for the specified data source or driver as a list of keyword-value pairs. kDSNMode should be passed as either kODBCSystemDSN, kODBCUserDSN or kODBCDriverInfo.
$getinfo() does not support File DSNs for which standard FileOps methods can be used to read/modify as required.
On return, lResult is defined with the following character columns:

  • KeyWord - The name of the DSN/driver attribute
  • Value - The value of the DSN/driver attribute

Example: Do tSess.$getinfo(lDSNInfo,lHostname,kODBCUserDSN) Returns #F

$setinfo()

$setinfo(cDSNName, kDSNMode, lData) writes the information contained in lData to the specified Data source or Driver key in the system information. lData should be defined with Keyword and Value columns as returned by $getinfo().
If kDSNMode is kODBCDriverInfo, this has the effect of modifying system information for the specified driver. cDSNName should contain the descriptive name of the ODBC Driver as opposed to the physical file name.
If kDSNMode is kODBCSystemDSN or kODBCUserDSN, this has the effect of modifying the specified data source.
$setinfo() does not register a new data source or driver. To properly create a data source; use the $configdsn() method instead. To properly register a driver, you should refer to the vendor's installation program.

Example: Do tSess.$setinfo(iDSNName,kODBCUserDSN,lDSNinfo) Returns #F

$configdsn()

$configdsn(kDSNMode, kRequestType, cDriverName, lAttributes ) allows the specified datasource to be created, modified or removed.
kDSNMode should be either kODBCSystemDSN or kODBCUserDSN. $configdsn() does not support configuration of File DSNs- for which an alternative method is provided. kRequestType should be passed as either kODBCAddDSN, kODBCModifyDSN or kODBCRemoveDSN. cDriverName should correspond with the descriptive name of the driver (i.e. not the physical file name).
lAttributes should be defined with two character columns and is used to pass keyword-value pairs to the driver manager sufficient to perform the required action. Usually this involves adding a single line to the list to identify the DSN to be created/modified/removed, for example:

KeyWord Value
DSN MyDataSourceName

but can also include other keywords that are allowed by the driver.
When $uselogonprompt is set to kODBCPromptNever, this prevents $configdsn() from opening setup dialogues. The DSN is created/modified silently using values read from the attribute list instead.

Example: Do sessObj.$configdsn(kODBCUserDSN,kODBCAddDSN,'SQL Server',lAttribList) Returns #F

$getoption()

$getoption(kOption, cAttribute) allows the value of an ODBC configuration attribute to be retrieved.
kOption should be passed as one of the following constants:

  • kODBCTrace - Requests the TRACE on/off flag
  • kODBCTraceLib - Requests the name and path to the ODBC trace library
  • kODBCTraceFile - Requests the name and path to the ODBC trace log
  • kODBCFileDSNDir - Requests the default directory containing file DSNs
  • kODBCPerfMon - Requests the Performance monitoring on/off flag
  • kODBCRetryWait - Requests the connection pool RetryWait timeout

On return, cAttribute contains the value of the requested option as a character string.

Example: Do sessObj.$getoption(kODBCFileDSNDir,iFileDSNDir) Returns #F

$setoption()

$setoption(kOption, cAttribute) allows the value of an ODBC configuration attribute to be modified.
kOption should be either

  • kODBCTrace - enable/disable ODBC tracing
  • kODBCTraceLib - assign the trace library name
  • kODBCTraceFile - assign the trace filename
  • kODBCFileDSNDir - assign the File DSN directory
  • kODBCPerfMon - enable/disable performance monitoring
  • kODBCRetryWait - assign the retry wait delay

cAttribute should contain a character string representing the new value for the specified configuration option.

Example: Do sessObj.$setoption(kODBCTraceFile,iTraceFile) Returns #F

Additionally, the session property; $uselogonprompt now accepts the following constant values:

  • kODBCPromptNever - Additional logon prompts are disabled
  • kODBCPromptComplete - Prompt for missing information only
  • kODBCPromptAlways - Always display a logon prompt

kODBCPromptAlways is used to force the ODBC Administrator library to display a configuration dialogue for example- when connecting to File DSNs.
As you can see above, several new constants have also been added to help with ODBC administration. These can be found in the Omnis Catalog (F9) listed under "ODBCDAM".

Example Library

The odbcadmin.lbs library uses the methods above to use to create an ODBC Administrator- similar to those provided by Microsoft and Apple, which can either be used stand-alone or as the starting point for your own ODBC administration tool.

odbcadmin.lbs for Studio 4.3
odbcadmin.lbs for Studio 10.2

 

Search Omnis Developer Resources

 

Hit enter to search

X