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:
Test.txt in the Windows 2003 Server SP 2 is like: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; }
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.Code:Enter CLSID: {00000514-0000-0010-8000-00AA006D2EA4} UNKNOWN: -2147467262 After CreateInstance
-2147467262 value for HRESULT is: interface is not compatible.
Someone have some idea?
Thanks in advance!!


Reply With Quote
Bookmarks