Link to home
Start Free TrialLog in
Avatar of medusaresearch2
medusaresearch2

asked on

Passing an ADO Connection to an AdoQuery in a DLL

I'm trying to pass an ADOConnection to an ADO query in a DLL.
When I try to activate the query I get an EOleException error.
I'm using Delphi 6 and am calling CoInitialize.
What am I missing or am doing wrong.
Any help would be appreciated.
TIA
Jeff
Avatar of Bracco
Bracco

Hi medusaresearch2,
this code works properly. Note that if you're passing strings, your first uses clause must be ShareMem in both DLL and project:

uses
  ShareMem,
  ...
  ADODb,
  ActiveX,
  ...;

...
...    
    try
{ CoInitialize  }
        CoInitialize(nil);
{ Connection createing }
        adoConn                  := TAdoConnection.Create(myComp);
        adoConn.ConnectionString := sConn;
        adoConn.LoginPrompt      := False;
        adoConn.Connected        := True;
    except
        on e: exception do
        begin
            WriteLog('   ===> Connection Error <===');
            WriteLog(e.Message);
            CoUnInitialize;
            raise;
        end;
    end;
...
{ Query }
    try
        qryIndex            := TAdoQuery.Create(myComp);
        qryIndex.Connection := adoConn;
        qryIndex.Close;
        qryIndex.SQL.Add('Select * From ' + sTableName);
        qryIndex.SQL.Add(' Where ' + sFilter + ' <> ' + #39 + #39);

        qryIndex.Prepared;
        qryIndex.Open;
        ...
        ...
Avatar of medusaresearch2

ASKER

Bracco,

I'm passing an existing ado connection to a routine in a DLL from the main program:

Main program:
   EditData( Ado );

DLL:
   procedure EditData( ADOConn : TAdoConnection ); //DLL routine def

In the DLL, the routine creates a form which has a query component.

  frmEditData := TfrmEditData.Create(Application);

The connection is then set for the query:

  adoQuery.Connection := ADOConn;

Then the query is executed and I get the EOleException error.

What am I missing?

TIA Jeff
Hi medusaresearch,
i'm trying to do the same, but i think the problem isn't in the adoConn or in the adoQuery. If the query is created properly i think there's no problem there.

Bracco
ASKER CERTIFIED SOLUTION
Avatar of Bracco
Bracco

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
Thanks, that fixed it.