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

Moving a Report from one Database to another

edited August 2002 in General
Following Problem:

A report is stored in an Oracle databas. Now I want to copy it to another
Oracle database
For that I saved the report into a rtm file and reloaded in my new database.
That works fine.
If I execute the report now directly, I got an error, because the report
still try to connect to the old database. It seems that the BDE-Alias is
also stored in the RTM file.
Only if I open it in design mode and store it again, I can run the report.

How can I avoid that?

The Environment:
Delphi 6
BDE 5.11
Oracle 8.1.7
Win2000
RB 6

Thanks in Advance

Nicolas

Comments

  • edited August 2002
    Set the database session at runtime. For example:

    uses
    daDataModule, daSQL, daQueryDataView, ppTypes;

    var
    lDataModule: TdaDataModule;
    lDataView: TdaDataView;
    lSQL: TdaSQL;
    begin

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

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

    if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
    begin
    lSQL := TdaQueryDataView(lDataView).SQL;
    lSQL.DatabaseName := 'myDB';
    lSQL.DatabaseType := dtOracle;
    end;

    end;
    end;

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

  • edited August 2002
    > Set the database session at runtime. For example:
    Can I do that also in the End-User Part?

    Regards
    Nicolas
  • edited August 2002
    As an end user in RB, you'll have to build the dataviews to connect to a
    specific database as defined in the datasettings of the data tab. You could
    build a little utility application that could load your end users templates,
    update the sql object as shown in the example code, and then save the
    templates to the new database. Then your user could run the reports using
    the new database connection. You can load templates and edit them as text,
    even if they are saved in binary as shown in the code below:

    {LOAD}
    procedure TForm1.Button1Click(Sender: TObject);
    var
    lsFileName: String;
    lFileStream: TFileStream;
    lTextStream: TMemoryStream;
    begin

    Button1.Enabled := False;
    Button2.Enabled := True;

    lsFileName := ExtractFilePath(ParamStr(0)) + 'example.rtm';

    lFileStream := TFileStream.Create(lsFileName, fmOpenRead);
    lTextStream := TMemoryStream.Create;

    try

    lFileStream.Position := 0;

    ObjectBinaryToText(lFileStream, lTextStream);

    lTextStream.Position := 0;

    Memo1.Lines.LoadFromStream(lTextStream);

    finally

    lFileStream.Free;
    lTextStream.Free;

    end;

    end;

    {SAVE}
    procedure TForm1.Button2Click(Sender: TObject);
    var
    lsFileName: String;
    lFileStream: TFileStream;
    lTextStream: TMemoryStream;
    lWriter: TWriter;
    begin

    Button2.Enabled := False;

    lsFileName := ExtractFilePath(ParamStr(0)) + 'example.rtm';
    DeleteFile(lsFileName);

    lFileStream := TFileStream.Create(lsFileName, fmCreate);
    lTextStream := TMemoryStream.Create;

    try

    Memo1.Lines.SaveToStream(lTextStream);

    lTextStream.Position := 0;

    ObjectTextToBinary(lTextStream, lFileStream);

    lWriter := TWriter.Create(lFileStream, 1024);
    try
    lWriter.WriteListEnd;
    finally
    lWriter.Free;
    end;

    lFileStream.Position := 0;

    finally

    lFileStream.Free;
    lTextStream.Free;

    end;

    end;



    Cheers,

    Jim Bennett
    Digital Metaphors

This discussion has been closed.