Home End User
New Blog Posts: Merging Reports - Part 1 and Part 2

Database Logon Dialog appears when previewing

edited March 2004 in End User
Good Evening All:

I have run into a problem that I cna't seem to get around.

I created a stand alone app to enable testing of the creation, import and
export of report templates for my client.

Everything went well and I began the process of incorporating the end-user
components into an existing application module. (copied the end-user
queries, datasources, pipelines, the report component, designer, explorer
and the data dictionary from the standalone app and pasted into existing
datamodule).

All the copied components were pointed to the appropriate session etc. and I
am able to compile and run the application and execute the explorer
component. All the templates are visible.

The problem arises when I try to preview a report.

A database logon dialog appears, asking for my username, password and the
database.

The database field displays the name of the session component from the test
application.

If I ignore the dialog, I get a 'Cannot Generate Report. Not Logged In'
error message.

If I enter my username and password, but leave the old session name or even
substitute the new session name, I get a TNS error that tells me I am trying
to use a connect string that Oracle does not recognize.

If I enter an actual database name, the logon dialog will disappear, but
will reappear for each datasource created on the data tab.

The report will eventually run in this manner and display the expected data.

Any ideas?

TIA

--
Geoff Dunmore
Rylex Software Systems
Box 346
Ruthven ON N0P 2G0
rylex@cogeco.ca

Comments

  • edited March 2004

    When you create a new Query DataView using DADE, the DatabaseName is saved
    as part of the definition. When the report loads, it tries to resolve the
    database name object reference.

    Please the following article for details...

    -------------------------------------------------
    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 daQClass.pas.

    -------------------------------------------------
    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
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited March 2004
    Nard:

    Thank-you for your quick response.

    Your solution works wonderfully for simple reports, but I continue to have
    problems with more complex reports that have linked/multiple dataviews.

    Does the database name need to be replaced for each seperate dataview?

    Would I be correct in assuming that one would have create a separate
    procedure that returned the count of dataview and then use this result to
    iterate through the dataviews array and apply the database update to each?

    Thanks in advance.

    --
    Geoff Dunmore
    Rylex Software Systems
    Box 346
    Ruthven ON N0P 2G0
    rylex@cogeco.ca
  • edited March 2004

    You are correct, you need to update the database name for each dataview by
    iterating thru the DataModule.DataViews[] array.

    example:

    for liIndex := 0 to myDataModule.DataViewCount-1 do
    begin
    lDataView := myDataModule.DataViews[liIndex];

    if lDataView is TdaQueryDataView then
    {call routine to extract the SQL object and update the name}

    end;




    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited March 2004
    Thank-you!

    Works like a charm.

    --
    Geoff Dunmore
    Rylex Software Systems
    Box 346
    Ruthven ON N0P 2G0
    rylex@cogeco.ca
This discussion has been closed.