HOME  |  NEWS  |  PRODUCTS  |  SUPPORT  |  ORDER  |  CORPORATE  
 

Tip #73 - Dynamic Database Connections


Category

Rave - Data Connections

Question

    I need to be able to change the AuthDesign property of my database connection at runtime so that I can connect to different servers depending on my customer's server settings. How would I do that?

Solution

    Changing your database connection properties prior to executing a report can easily be done as indicated below. The example uses parameters needed to make an Interbase connection. The DataSource property may change depending on the database that you are using. To see the format needed for this property simply place a break point on the code just prior to the DataSource property being assigned and you will be able to see what is expected in this property. This is assuming that you have set up the Database property correctly in the Rave Designer.

    Delphi Example:
    uses
      RvDLInterbase, RvDatabase;
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Database: TRaveDatabase;
    begin
      RvProject1.Open;
    
      Database := TRaveDatabase(RvProject1.ProjMan.FindRaveComponent('Database1', nil));
      if Assigned(Database) then begin
        Database.AuthRun.Datasource := 'ServerIP:/datapath/test.gdb';
        Database.AuthRun.Username := 'sysdba';
        Database.AuthRun.Password := 'ThePassword';
      end; { if }
      RvProject1.ExecuteReport('Report1');
    end;

    C++ Builder Example:
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
      TRaveDatabase* Database;
    
      RvProject1->Open();
    
      Database = dynamic_cast<TRaveDatabase*>(RvProject1->ProjMan->FindRaveComponent("Database1", NULL));
      if (Database != NULL) {
        Database->AuthRun->Datasource = "ServerIP:/datapath/test.gdb";
        Database->AuthRun->Username = "sysdba";
        Database->AuthRun->Password = "ThePassword";
      }// if
      RvProject1->ExecuteReport("Report1");
    }
    

Tip created by Nevrona Designs - Email : support@nevrona.com - Web : http://www.nevrona.com

Date Created: 4/8/2003 12:35:46 PM - Date Last Updated: 4/8/2003 12:43:16 PM