Home DADE

Recreate an ADO Connection from a Template (RTM/DB)

edited November 2004 in DADE
We have the end user reporting function working using a set of ADO
components. Name of the connection is euDatabase. Have been using as a
general purpose report builder and seems to work ok. We use .udl files to
control the ADO connections.

When exporting the report and loading in another program (or
loadfromdatabase) we have a problem with the report, when printed, not being
able to make the ADO connection - defaults to an ODBC. We have traced to
the fact that the ADO connection component in the 2nd program using the
.rtm/database record has a different name than the original program that
built the report.

This raises the question of moving reports around to different programs -
means we need to have an ability to have the calling program name the ADO
connection the same as the original and build with similar characteristics
(primarily the connection string for the .udl used). Thought maybe we could
use the information from the loaded report to recreate the connection but it
doesn't look like the report template has enough info to recreate the ADO
connection.

Is there a way to change the report, once loaded to a report component, to
use a different connection? And how can we tell what .udl is needed.

Comments

  • edited November 2004

    -------------------------------------------------
    Tech Tip: How to modify the DatabaseName stored
    with a DADE Query
    -------------------------------------------------

    Currently when DADE is used to create dataviews,
    the DatabaseName is stored as part of the query
    definition. (This is consistent with Delphi's
    approach to specifying a database connection for
    a Query object).

    In some cases, you may decide that the
    DatabaseName needs to be modified at a later date.

    We recommend that the DatabaseName
    refer to a TDatabase connection component or to
    an Alias to provide flexibility for changing
    the connection parameters.

    A second way to handle this issue is to implement
    some code that specifies a DatabaseName
    whenever a template is loaded. This can be accomplished
    by using the Report.Template.OnLoadEnd event.


    1. Declare an event-handler procedure in the private
    section of your form declaration.

    type
    myForm = class(TForm)
    private
    procedure ReportTemplateLoadEndEvent(Sender: TObject);
    public
    end;


    2. Use the FormCreate event to assign the event-handler to
    the event property.

    procedure myForm.FormCreate(Sender: TObject)
    begin
    Report1.Template.OnLoadEnd := ReportTemplateLoadEndEvent;

    end;

    3. Add code to the event-handler to specify the database name.


    procedure myForm.ReportTemplateLoadEndEvent(Sender: TObject)
    var
    lSQL: TdaSQL;

    begin
    if GetSQLObject(Report1, lSQL) then
    begin
    lSQL.DatabaseName := Designer.DataSettings.DatabaseName;
    SetSQLObject(Report, lSQL);
    lSQL.Free;

    end;

    end;


    4. Below is a tech tip for extracting the SQL object
    from a report. TdaSQL is a class defined in daSQL.pas.
    The example code extracts only DataViews[0]. If the report
    contains multiple dataviews, you will need to iterate thru
    all of the entries in the DataViews[] array.

    -------------------------------------------------
    Tech Tip: How to access the SQL object associated
    with a Report created using DADE
    -------------------------------------------------

    uses
    daDatMod;


    function GetSQLObject(aReport: TppReport; var aSQL: TdaSQL): Boolean;
    var
    lDataModule: TdaDataModule;
    lDataView: TdaDataView;
    begin

    aSQL := TdaSQL.Create(nil);

    {get the datamodule}
    lDataModule := daGetDataModule(aReport);

    if (lDataModule <> nil) then
    begin
    lDataView := lDataModule.DataViews[0];

    if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
    aSQL.Assign(TdaQueryDataView(lDataView).SQL);

    end;

    Result := (aSQL <> nil);

    end;


    procedure SetSQLObject(aReport: TppReport; aSQL: TdaSQL);
    var
    lDataModule: TdaDataModule;
    lDataView: TdaDataView;
    begin


    {get the datamodule}
    lDataModule := daGetDataModule(aReport);

    if (lDataModule <> nil) then
    begin
    lDataView := lDataModule.DataViews[0];

    if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
    TdaQueryDataView(lDataView).SQL := aSQL;

    end;

    end;





    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com

    --
    Nard Moseley
    Digital Metaphors Corporation
    www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited November 2004
    Hello Nard,

    Thank you very much for your high-tech tips, I combined them and created a
    new method to fix the DatabaseName,
    even if the report contains multiple Dataviews. Here is my solution to
    resolve this issue:

    procedure TfrmMain.FixDatabaseName;
    var
    index: integer;
    aSQL: TdaSQL;
    lDataModule: TdaDataModule;
    lDataView: TdaDataView;
    begin
    //--- get a new SQL object
    aSQL := TdaSQL.Create(nil);
    //--- get the datamodule
    lDataModule := daGetDataModule(report);
    if (lDataModule <> nil) then begin
    index := 0;
    //--- loop through all the Dataviews
    while (index < lDataModule.DataViewCount) do begin
    //--- get the Dataview
    lDataView := lDataModule.DataViews[index];
    //--- validate the Dataview
    if (lDataView <> nil) and (lDataView is TdaQueryDataView) then begin
    aSQL.Assign(TdaQueryDataView(lDataView).SQL);
    // ShowMessage( 'OLD DB: ' + aSQL.DatabaseName + #13#10 +
    // 'NEW DB: ' + designer.DataSettings.DatabaseName );
    aSQL.DatabaseName := designer.DataSettings.DatabaseName;
    TdaQueryDataView(lDataView).SQL := aSQL;
    end;
    inc(index);
    end;
    end;
    end;

    Please let me know if I'm missing something.

    Best regards,
    Jorge I.

    to
    to
    programs -
    ADO
    characteristics
    but
    ADO
    to
This discussion has been closed.