vc中oracle如何通过odbc数据源名取得对应数据库名?

解决方案 »

  1.   

    SQLRETURN SQLGetInfo(
         SQLHDBC     ConnectionHandle,
         SQLUSMALLINT     InfoType,
         SQLPOINTER     InfoValuePtr,
         SQLSMALLINT     BufferLength,
         SQLSMALLINT *     StringLengthPtr);SQLUSMALLINT     InfoType:
    SQL_DATA_SOURCE_NAME returns the value passed as DSN to SQLConnect, or SQLDriverConnect; returns an empty string if no DSN is specified.
    SQL_DATA_SOURCE_READ_ONLY returns 'N'.
    SQL_DATABASE_NAME returns a full UNC path to the current database if the data source is a database. If the data source connects to a directory of tables, the function returns the path to the directory.
    SQL_DBMS_NAME returns "Visual FoxPro".
    SQL_DBMS_VER returns "03.00.0000".
    SQL_DEFAULT_TXN_ISOLATION returns SQL_TXN_READ_COMMITTED. Dirty reads are not possible, but nonrepeatable reads and phantoms are possible.
    SQL_DRIVER_HDBC is implemented by the Driver Manager.
    SQL_DRIVER_HENV is implemented by the Driver Manager.
    SQL_DRIVER_HLIB is implemented by the Driver Manager.
    SQL_DRIVER_HSTMT is implemented by the Driver Manager.
    SQL_DRIVER_NAME returns "vfpodbc.dll".
    SQL_DRIVER_ODBC_VER returns "02.50" (SQL_SPEC_MAJOR, SQL_SPEC_MINOR).
    SQL_DRIVER_VER returns "01.00.0000".
    更多的内容参考MSDN给出你具体用法:
    /*===================================
    函数功能:得到当前连接的数据源名称信息
    ====================================*/
    CString  CLeftView::GetCurrentDBInfo(HDBC hdbc)
    {
    CString strCurDB;
    char buf[200];
    short num;
        //获得当前连接数据库的信息
        SQLGetInfo(hdbc,SQL_DATA_SOURCE_NAME,buf,sizeof(buf),&num);
    strCurDB.Format("%s",buf);
    return strCurDB;
    }