Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing an ADO Connection to an AdoQuery in a DLL

Posted on 2004-05-02
5
Medium Priority
?
1,820 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:medusaresearch2
  • 3
  • 2
5 Comments
 

Expert Comment

by:Bracco
ID: 10975133
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;
        ...
        ...
0
 

Author Comment

by:medusaresearch2
ID: 10978704
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
0
 

Expert Comment

by:Bracco
ID: 10984009
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
0
 

Accepted Solution

by:
Bracco earned 500 total points
ID: 10984256
Hi Medusaresearch2,
i tried and the code works properly. In a main program i create the connection.

DLL
------
procedure editData(adoConn: TAdoConnection);
var frmEdit: TfrmEditFields;
begin
    frmEdit                  := TfrmEditFields.Create(adoConn);
    frmEdit.ShowModal;
    frmEdit.freeMemory;
    frmEdit.Free;
end;

frmEdit
---------
constructor TfrmEditFields.create(adoConn: TAdoConnection);
begin
    inherited Create(nil);
    myConn := TAdoConnection.Create(self);
    myConn := adoConn;
end;

procedure TfrmEditFields.FormShow(Sender: TObject);
begin
    AdoQry.Connection := myConn;
    AdoQry.Close;
    AdoQry.SQL.Clear;
    AdoQry.SQL.Add('Select * from TableName');
    AdoQry.Prepared := True;
    AdoQry.Open;

    if not ( AdoQry.Eof ) then
    begin
        edtField1.Text := AdoQry.FieldByName('Field1').AsString;
        edtField2.Text := AdoQry.FieldByName('Field2').AsString;
        edtField3.Text := AdoQry.FieldByName('Field3').AsString;
    end;
end;

Hope it helps you


0
 

Author Comment

by:medusaresearch2
ID: 10988146
Thanks, that fixed it.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question