Class OdbcManager() Professional

Manage ODBC data sources

Description

The OdbcManager()-class provides acces to the ODBC manager. It is used to administer ODBC data sources, either interactively or programmatically.

Class methods
:new()
Creates an instance of the OdbcManager() class.
:getLastError()
Retrieve error information.
Methods
:addUserDSN()
Adds a user data source.
:removeUserDSN()
Removes a user data source.
:configUserDSN()
Configures (modifies) a user data source.
:addSystemDSN()
Adds a system data source.
:removeSystemDSN()
Removes a system data source.
:configSystemDSN()
Configures (modifies) a system data source.
:removeDefaultDSN()
Removes thr default DSN.
:validateDSNName()
Validates a DSN name.
:showAdministrator()
Shows ODBC administrator dialog.
:createDSNDialog()
Displays a wizard dialog to create a DSN.
:getDrivers()
Retrieves a list of installed ODBC drivers.
:getDSNs()
Retrieve a list of data sources.
:getOdbcInstallPath()
Returns the ODBC installation directory.
Examples
Create, configure and remove a DSN
// The sample shows how to add, configure and 
// remove a named user data source 

#include "sqlcmd.ch" 

PROC Main() 
LOCAL oMgr 
LOCAL cDsn, cDriver 

    oMgr := OdbcManager():new() 
    // the name of the DSN and the driver to use 
    cDsn := "Test" 
    cDriver := "Microsoft dBase-Treiber (*.dbf)" 

    // check if name can be used 
    IF !oMgr:validateDSNName(cDsn) 
       ? "DSN name invalid:" 
       ? "Error(s):",oMgr:getLastError() 
    ENDIF 

    cDsn := "DSN="+cDsn 

    // try to configure DSN, if DSN exists 
    IF oMgr:configUserDsn(cDriver, cDsn) 
       ? cDsn + " configured" 
    ELSE 
       // otherwise, create a new DSN 
       IF !oMgr:addUserDsn(cDriver, cDsn) 
         ? oMgr:getLastError() 
       ELSE 
         ? cDsn + " added." 
       ENDIF 
    ENDIF 

    // remove the specified DSN 
    IF oMgr:removeUserDsn(cDriver, cDsn) 
         ? cDsn + " removed." 
    ELSE 
         ? "Error(s):", oMgr:getLastError() 
    ENDIF 
 RETURN 
Getting information and working interactively
// This sample demonstrates how to retrieve information 
// about data sources, and how to work 
// with predefined dialogs 

#include "sqlcmd.ch" 

PROC Main() 
LOCAL oMgr 
LOCAL cDsn, cDriver 

    oMgr := OdbcManager():new() 
    // list all installed drivers 
    ? oMgr:getDrivers() 
    // list data sources 
    ? oMgr:getDSNs() 
    // return path to ODBC DLL's 
    ? oMgr:getOdbcInstallPath() 

    // pop-up the ODBC Administrator dialog 
    // to let the user manage data sources interactively 
    oMgr:showAdministrator() 

    // pop-up the "Create Data Source"- dialog 
    // to let the user create a new data sources interactively 
    oMgr:createDSNDialog() 
 RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.