[RESOLVED] ADO compatibility
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [RESOLVED] ADO compatibility

  1. #1
    Join Date
    Feb 2005
    Location
    Madrid (Spain)
    Posts
    511

    [RESOLVED] ADO compatibility

    Hi gurus.

    Iím having a trouble with ADO. I have this code (below), it works fine in a developer machine (Windows 7 and Visual studio 10) but compiled program not works under Windows Server 2003 SP 2.

    the cpp file:

    Code:
    #include "stdafx.h"
    #include <string> 
    #include <iostream>
    
    
    using namespace std;
    
    
    #import <C:\\Program Files\\Common Files\\System\\ado\\msado15.dll> no_namespace rename("EOF", "adoEOF")
    
    
    _ConnectionPtr bdConnect;
    
    
    bool OpenBD(string szConexion, int nTimeOut_);
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {    
        string sConnection = "driver={sql server};SERVER=myserver;Database=mydb;UID=myuser;PWD=mypass";
        
        bool bRes = true;
        try {
            bRes = OpenBD(sConnection, 10);
        } catch (string sError) {
            cout << sError << endl;
        }
    
    
        Sleep(5000);
    
    
        return 0;
    }
    
    
    
    
    bool OpenBD(string sConexion, int nTimeOut_) {
        FILE *pf = fopen("Test.txt", "wt");
        DWORD dIniCount = GetTickCount();
        string sConexionRes;
        char sAux[100];
    
    
        bool bError = false;
        HRESULT _hr = S_OK;
        try {
            ::CoInitialize(NULL);        
            fprintf(pf, "Enter\n");
            fflush(pf);
            CLSID IID;
            IID = __uuidof(Connection);        
            LPOLESTR sIID;        
            StringFromCLSID(IID, &sIID);
            char sNombre[1000];
            WideCharToMultiByte(CP_ACP, 0, sIID, wcslen(sIID), sNombre, sizeof(char) * wcslen(sIID), NULL, NULL);
            sNombre[wcslen(sIID)] = '\0';
            fprintf(pf, "CLSID: %s\n", sNombre);
            fflush(pf);
    
    
            _hr = bdConnect.CreateInstance(__uuidof(Connection));
            
            if(_hr == S_OK) {
                fprintf(pf, "S_OK\n");
                fflush(pf);
            } else if(_hr == S_FALSE) {
                fprintf(pf, "S_FALSE\n");
                fflush(pf);
            } else if(_hr == RPC_E_CHANGED_MODE) {
                fprintf(pf, "RPC_E_CHANGED_MODE\n");
                fflush(pf);
            } else {
                fprintf(pf, "UNKNOWN: %d\n", _hr);
                fflush(pf);
            }
            
            fprintf(pf, "After CreateInstance\n");
            fflush(pf);
    
    
            if (FAILED(_hr)) _com_issue_error(_hr);
            fprintf(pf, "After: _com_issue_error(_hr);\n");
            fflush(pf);        
        } catch(_com_error &e) {
            DWORD dCountError = GetTickCount();        
            sConexionRes = sConexion;
            sConexionRes += "\nConnection error description:\n";
            BSTR sComError;
            IErrorInfo *pErrorInfo = e.ErrorInfo();
            pErrorInfo->GetDescription(&sComError);        
            _bstr_t bstr_t(sComError);
            string strError(bstr_t);
            sConexionRes += strError;
            
            sprintf(sAux, "\nHRESULT value: %x", _hr);        
            sConexionRes += sAux;
    
    
            sprintf(sAux, "\nConnection timeout is defined to %d seconds\n",nTimeOut_);
            sConexionRes += sAux;
    
    
            sprintf(sAux, "Elapsed time: %d milliseconds\n", dCountError - dIniCount);
            sConexionRes += sAux;
        
            throw sConexionRes;
        }
    
    
        DWORD dConnect = GetTickCount();
        sConexionRes = sConexion;
        sprintf(sAux, "\nConnection established. Elapsed time: %d milliseconds\n", dConnect - dIniCount);
        sConexionRes += sAux;
    
    
        cout << sConexionRes << endl;
    
    
        fclose(pf);
    
    
        return TRUE;
    }
    Test.txt in the Windows 2003 Server SP 2 is like:

    Code:
    Enter
    CLSID: {00000514-0000-0010-8000-00AA006D2EA4}
    UNKNOWN: -2147467262
    After CreateInstance
    In the registry (Windows 2003 Server SP 2) the key {00000514-0000-0010-8000-00AA006D2EA4} is HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ADODB.Connection that it's the same in the developer machine.

    -2147467262 value for HRESULT is: interface is not compatible.

    Someone have some idea?

    Thanks in advance!!

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,390

    Re: ADO compatibility

    Victor Nijegorodov

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center