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

Problem with End User connecting to the wrong database.

edited September 2003 in End User
Hi,

I am implementing a Custom Report Viewer with a Custom End User Auto Search
box.

When the report View is called, it will connect to a Database, show the user
my custom Auto Search filter and then launch the report.

Code as follows.

Application.ProcessMessages;
FReport := TppReport.Create(Application);
FReport.Template.FileName := FFileName;
FReport.Template.LoadFromFile;
FReport.PreviewFormSettings.WindowState := (wsMaximized);
FReport.PreviewFormSettings.ZoomSetting := zs100Percent;
FReport.DeviceType := dtScreen;
ppRegisterForm(TppCustomAutoSearchDialog, TfrmCustomSearchDialog);
FReport.Print;
ppUnRegisterForm(TppCustomAutoSearchDialog);
FReport.Free;

Before this code I have the following code.

If ADOConnection.ConnectionExists(EnpriseInfo.ApplicationAutoAlias) Then
Begin

ADOConnection.SetCurrentConnectionByName(EnpriseInfo.ApplicationAutoAlias);
ADOConnection.ReConnectDB;
EnpriseInfo.ApplicationAlias := EnpriseInfo.ApplicationAutoAlias;
End;

This codes changes the ADOConnection ('MainConnection') to connect to the
correct database depending on details in the ParamStr.
This is working 100% as the CustomAutoSearch form is getting data back from
the correct database.

ADOConnection.ReConnectDB; =
Procedure TEnpriseConnections.ReConnectDB;
Begin
With ConnectionDM.MainConnection Do
Begin
Connected := False;
ConnectionString := FormatConnectionString(FCurrentConnection);
Connected := True;
End;
End;

The problem is the Report is not connecting to the New Database, it is
connecting to the Database that was specified Before the ReConnectDB was
called. Eg Design Time ConnectionString;

How can I fix this?

Regards,

Daniel

Comments

  • edited September 2003
    Further to this.
    If I open my DataModule that has the TADOConnection object in it
    And change the ConnectionString OnCreate of the DataModule.
    Then the Report works with the Database.

    It appears that Somehow the Report is getting the Connection Details on the
    Create of the DataModule, even though the Report object itself isn't created
    yet. Please Help.

    Daniel

  • edited September 2003
    Fixed
    Pls Ignore posts
    Dan
This discussion has been closed.