set Databasename in IBXquery inside report at runtime

Hello,

Im am using a IBXDatabse inside FastReport. The Database can be installed anywhere and correct hostname/databasenae are only known at runtime.
I Use this code to set the connection-parameters:
begin
showmessage( <Hostname>+':'+<DBName>);
  IBXDatabase1.connected:=false;
  if <Hostname>='' then
     IBXDatabase1.DatabaseName := <DBName>
  else
     IBXDatabase1.DatabaseName := <Hostname>+':'+<DBName>;      
  IBXDatabase1.connected:=true;                             
end.

When I start the Report I see the message showmessage( <Hostname>+':'+<DBName>); with the correct values but after that there is an exception "Databasename not defined in IBXDatabase1".
If I define a "dummy" databasename in IBXDatabase1 the exception is "can not open file [dummy-filenam]".

IBXDatabase1 is set conected=false in the report-template, so I don't know why FastReport tries to connect it without or before the code runs.

How to setup the report so that it does open the database AFTER setting the right databasename?

Regards,
Siegbert

Comments

  • gpigpi
    edited 7:01PM
    Use in the Delphi code:
    var Connect: Boolean; 
    implementation {$R *.dfm} 
    procedure TForm1.FormCreate(Sender: TObject); 
    begin 
      Connect:=False; 
      frxReport1.LoadFromFile('C:\test.fr3'); 
      Connect:=True; 
      TfrxADODataBase(frxReport1.FindObject('ADODatabase1')).Connected := False; 
      TfrxADODataBase(frxReport1.FindObject('ADODatabase1')).DatabaseName := 'Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Program Files\FastReports\FastReport 4\Demo\Main\demo.mdb'; 
      TfrxADODataBase(frxReport1.FindObject('ADODatabase1')).Connected := True; 
      frxReport1.ShowReport(); 
    end;
     
    procedure TForm1.frxReport1BeforeConnect(Sender: TfrxCustomDatabase; 
    var Connected: Boolean); 
    begin 
      if not Connect then 
        Connected:=False; 
    end;
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.