Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2008
    Posts
    26

    Question Unanswered: [VC++]Error when retrieving column information for tables (OpenSchema function)

    Hello !

    I use ADO to request column information for tables on the ORACLEserver (not supported when connecting to mainframes).
    MSDN indicates that the solution is : OpenSchema(ADODB::adSchemaColumns, varData). So, my remark is that Oracle case isn't mentionned everywhere in the Microsoft documents !!!

    This is the codes :
    Code:
    //Initialization of the connection (m_pConnection)
    
    int CHowToADOView::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        HRESULT hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection));
        if (FAILED(hr))
    	 {
    		AfxMessageBox(_T("CREATE CONNECTION INSTANCE ERROR !!!"));
    	 }
        m_pConnection->CursorLocation = ADODB::adUseClient;
        HRESULT hr2 = m_pConnection->Open(L"Provider=MSDAORA.1;Password=systemtest1;User ID=system;Data Source=test1sid_10.12.1.2;Persist Security Info=True", L"",L"", ADODB::adConnectUnspecified);
        if (FAILED(hr2))
    	 {
    		AfxMessageBox(_T("OPEN CONNECTION ERROR !!!"));
    	 }
        return 0;
    }
    
    //BUTTON WHICH EXECUTES THE OPENSCHEMA
    void CHowToADOView::OnBnClickedOpenschema2()
    {
        // open it
        try
        {
            _variant_t vSourceSchema = L"MYSCHEMA";
            _variant_t vSource = L"TABLE1";
    
            _variant_t varCriteria[3];
            _variant_t vtNull;
            vtNull.vt = VT_NULL;
            varCriteria[0] = vtNull;
            varCriteria[1] = vtNull;
            varCriteria[2] = vSource;
    
            // Creating a safe array of variants with 3 elements.
            VARIANT varData;
            SAFEARRAY FAR* psa;
            SAFEARRAYBOUND rgsabound[1];
            rgsabound[0].lLbound = 0;
            rgsabound[0].cElements = 3;
            psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
    
            // Fill the safe array.
            for(long lIndex = 0 ; lIndex < 3 ;lIndex++)
            {
                SafeArrayPutElement(psa, &lIndex,&varCriteria[lIndex]);
            }
    
            // Initialize the safearray.
            varData.vt = VT_VARIANT | VT_ARRAY;
            V_ARRAY(&varData) = psa;
    
            ADODB::_RecordsetPtr tempRS;
            tempRS = NULL;
            tempRS.CreateInstance( __uuidof( ADODB::Recordset ) );
            tempRS = m_pConnection->OpenSchema(ADODB::adSchemaColumns,varData);
            if (!(tempRS->GetADOEOF()))
                AfxMessageBox(_T("THERE IS SOMETHING in tempRS"));
            else
                AfxMessageBox(_T("THERE IS NOT SOMETHING in tempRS"));
        }
        catch (_com_error& e) 
        {
            CString str = (CString)(e.Description().GetBSTR()) +"\r\n"+ (CString)(e.ErrorMessage());
            AfxMessageBox(str);
        }
    }
    If the connection string is for Oracle (like here), there is an exception which is caught by the try...catch...
    In Sql server, it works correctly even if we fill the criteria vtCriteria[] with any values !

    Perhaps, doesn't retrieving column infos work for Oracle ??

  2. #2
    Join Date
    Feb 2008
    Posts
    26
    As a matter of fact, this thread is Oracle in C++ (60% Oracle and 40% Visual C++).
    Syntax of OpenSchema :
    recordset = connection.OpenSchema ( QueryType, Criteria, SchemaID )

    So, what does the Criteria Array contain exactly ? What to fill in each case ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •