Link to home
Start Free TrialLog in
Avatar of cytay
cytayFlag for Malaysia

asked on

Client compiled COM dll can not initialzed ADO Command at server side !

Dear all,

    Lately I'm developing data access tier in COM way. I face a problem where the COM dll generated at my PC can not initialize ADO Command at server. The dll has been registered at server before I use its service. The error message is "No such interface supported.".

    But if I compile the codes at server side, the dll can initialize ADO Command. Can anyone out there tell me a way to solve this ASAP !? Thanks in advance !

The way I initialize ADO Command is as below...
_CommandPtr pADOCommand = NULL;
TESTHR(pADOCommand.CreateInstance(__uuidof(Command)));
Avatar of ambience
ambience
Flag of Pakistan image

can explain a bit more ? . if you compile it at server it works fine and if at client then it wont ? , the dll is always registered at the server ?

>>> the COM dll generated at my PC can not initialize ADO Command at server.

what do u mean by ADO command at server , are you tryint to access datasource at server using ADO ?

>>> dll has been registered at server before I use
its service.

How are u using its services ?
Avatar of cytay

ASKER

Dear ambience,

Thanks for your immediate reply. I really appreciate it.

For your first question...
I compiled codes at my PC, then I copied the generated dlls to server for registration. I used Component Service to register the dlls. The ADO Command initialization at server failed.
I copied codes to server from my PC, then I compiled codes at server. I did the same way registration as the previous case. The ADO Command initialization at server worked.

For your second and third questions...
My data access tier scenario is The COM dlls will use ADO components' services to do the data operations on database server. The COM dlls and ADO components should be placed at the same server, but the database server can be any server that installed MS SQL Server. Understand !?
Avatar of AssafLavie
AssafLavie

First of all, you don't have to initialie smart pointers to NULL.
To your question: Have you made sure that ADO is installed on both machines; both at the same version?
Avatar of cytay

ASKER

Dear AssafLavie,

Thanks for the prompt response. Setting the smart pointer or any pointer to NULL is my habit. Will this approach cause the problem ? Meanwhile, I installed the same latest MDAC SDK at my PC and server. Its version is 2.6.

So...
this is strange , the only problem i could have expected was version in-consistencies , you have the same SDK and ADO dlls so that is realy strange..

Try compiling it on server and copying to client (i mean the other way around), does that work ?
Setting the smart pointer to NULL is redundant, but it won't cause any errors.
Try breaking the _CommandPtr instanciation down to it's lower level APIs.
Try calling CoCreateInstace and getting an IUnknown *.
Then try to QI it to _Command.
Tell us which function fails and what error code it returns.
Avatar of cytay

ASKER

Dear ambience & AssafLavie,

I have tried the other way of testing. It works fine. Is it because I compiled the codes at server ?

Then I have tried the way suggested by AssafLavie. It failed. The following is the code I wrote for testing...
IUnknown* pIUnknown = NULL;
m_lError = CoCreateInstance(_uuidofCommand),
                            NULL,
                            CLSCTX_ALL,
                            _uuidof(IUnknown),
                            (void**)&pIUnknown);

if (FAILED(m_lError))
{
    m_lError = -1;
    m_strError = _T("CoCreateInstance fail");
    return -1;
}

m_lError = pIUnknown->QueryInterface(_uuidof(_Command),
                                     (void**)&pADOCommand);

if (FAILED(m_lError))
{
    m_lError = -1;
    m_strError = _T("QueryInterface fail");
    return -1;
}
so where was the error ? CoCreateInstance or QueryInterface ?
Avatar of cytay

ASKER

Dear ambience & AssafLavie,

I have tried the other way of testing. It works fine. Is it because I compiled the codes at server ?

Then I have tried the way suggested by AssafLavie. It failed. The following is the code I wrote for testing...
IUnknown* pIUnknown = NULL;
m_lError = CoCreateInstance(_uuidofCommand),
                            NULL,
                            CLSCTX_ALL,
                            _uuidof(IUnknown),
                            (void**)&pIUnknown);

if (FAILED(m_lError))
{
    m_lError = -1;
    m_strError = _T("CoCreateInstance fail");
    return -1;
}

m_lError = pIUnknown->QueryInterface(_uuidof(_Command),
                                     (void**)&pADOCommand);

if (FAILED(m_lError))
{
    m_lError = -1;
    m_strError = _T("QueryInterface fail");
    return -1;
}
Avatar of cytay

ASKER

QueryInterface ! The error message is "No such interface supported". So...
First an alternative
hr = pADOCommand.CreateInstance(_T("ADODB.Command"));
try using this one !!

also as a general practice its better to use object in __uuidof() than its type so

TESTHR(pADOCommand.CreateInstance(__uuidof(Command)));

can be safely converted to

TESTHR(pADOCommand.CreateInstance(__uuidof(pADOCommand)));

use __uuidof(pADOCommand) and then see if it makes any difference ?
Teh code is obviuosley fine the way it is - since it works on another machine, right?
I assume then that the problem is with the library installation or something.
Try creating a Command object using VB on the problematic machine.
Avatar of cytay

ASKER

Dear ambience,

For the first approach, the error message is "No such interface supported.". And the second approach's result is still fail. Its error message is "Class not registered.".

I felt so sorry to trouble and disappoint you here.
No such interface was expected ofcourse since __uuidof has same effect with type and object , and class not registered is also fairly obvious.

My fault i told u to do this

TESTHR(pADOCommand.CreateInstance(__uuidof(pADOCommand)));

when i had wanted you to do the following

m_lError = pIUnknown->QueryInterface(_uuidof(pADOCommand),
                                    (void**)&pADOCommand);

I am extremely sorry for this causalness.
But there appears to be a problem with installation.



Avatar of cytay

ASKER

Dear ambience,

For the first approach, the error message is "No such interface supported.". And the second approach's result is still fail. Its error message is "Class not registered.".

I felt so sorry to trouble and disappoint you here.
Avatar of cytay

ASKER

Dear all,

I have tried the testing on VB at local PC. The ADO Command works well. For the suggestion made by ambience, the same error happened as previous one, "No such interface supported.". For your information, this error happened while doing a remote call, and the dll which stored at server is generated at local pc. Therefore...
>>> while doing a remote call
can explain what you mean by remote call ?
Avatar of cytay

ASKER

Dear ambience,

A remote call means... The COM dlls are run at server, my program which executed from my PC to get the services from the dlls. It works like DCOM.
instead of using _uuidof try using the ProgId - ADODB.Command -

TESTHR(pADOCommand.CreateInstance("ADODB.Command"));

I am assuming you are using _com_ptr_t


Avatar of cytay

ASKER

Dear ShaunWilde,

    Thanks for the advice. I will test your suggestion next Monday. Happy weekend !
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since nobody had a solution for you.

The link to the Community Support area is: https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner

Avatar of cytay

ASKER

This question has been here for quite some times, but no one can give me a satisfied answer. Therefore I have to delete this question. Before doing so, I would like to thank those who assisted me. :o)
ASKER CERTIFIED SOLUTION
Avatar of ComTech
ComTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial