ASTA Servers and Multiple DataSources


ASTAAdoServer Multi AdoConnection support

 

This ADO Server allows multple ADOConnections to be created on the fly so that AstaClientDatasets can use the Database:String property to access any number or Databases on the server.

 

Other ASTA servers have been coded to allow for multiple Datasources including the AstaOdbcServer, AstaDbisamServer and AstaBDEServer. There is also a multi-datasource ASTA ISQL Demo tutorial that demonstrates this feature.

 

How to define Availble Databases on the server.

==============================================

ASTAClientDataSets have a Database:String property that can be populated from ASTA servers so there is a design time pulldown of Database choices. To do this the AstaServer must code the OnFetchMetaData Event to return a TAstaDataSet in response to an mdDBMSName Metarequest from AstaclientDatasets.

 

The server must append the DbmsDataSet and define a value in the Database field that will stream back to the remote clientdataset.

 

This ADO Server contains a new menu option of Manager Aliases to allow Alias information to be defined and save to file by a TAstaDataSet calling SaveToFile.

 

The SetupDBMSDataSet call on the server populates the DBMSDataSet.

 

procedure TForm1.SetupDBMSDataBase;

var

i:Integer;

d:TAstaDataSet;

begin

With AstaDataModule do begin

  with DBMSDataSet do begin

    if FileExists(AliasDataSetFileName) then begin

     D:=TAstaDataSet.Create(nil);

     try

      d.LoadFromFilewithFields(AliasDataSetFileName);

      //add the main one you login on or the one you set the ADOConnection to on the datamodule

      AppendRecord([AstaServerSocket1.AstaServerName,'Main', ExtractFileName(Application.EXEName)]);

      while not d.eof do begin

       AppendRecord([AstaServerSocket1.AstaServerName, d.FieldByName('Alias').Asstring, '', ExtractFileName(Application.EXEName)]);

       d.next;

      end

      finally

      d.free;

      end;

     end else AppendRecord([AstaServerSocket1.AstaServerName, AstaServerSocket1.DataBaseName, '', ExtractFileName(Application.EXEName)]);

  end;

  UpdateAstaAlias(DBMSDataSet);

 end

end;

 

How to have server side database calls react to the Database:String property coming from the client

 

AstaclientdataSets will send their Database:String property to ASTA Servers on every database request. the Server must be able to respond to these requests by using or creating ADOConnections that are then connected to the ADO Database components sitting on the server AstaDataModule.

 

An FDatabaseList is used on the server to store the Alias Names and the AdoConnections that are created on the server in response to a client request for a particular Database.

 

This works in all 3 ASTA threading models and will create a list of Aliases with TAdoConnection components stored in the FDatabaseList.Objects property. When first adding a TAdoConnection that does not exist there may be a slight

delay as the AdoConnection connects to the server, depending on which database you are using but after that it will be very fast and efficient.

 

Note: when you define an Alias, build a Connection string and paste it into the memo field on the AliasManager setup form. this will be used to connect to the AdoConnection created on the fly.

 

 

 

 function TAstaDataModule.GetADOConnection(ClientSocket: TCustomWinSocket; Alias, FileName: string): TComponent;

 

var

  spot: Integer; Ad: TAdoConnection;

begin

  result := ADOConnection;

  if Alias = '' then exit;

  //add a line here if you want to skip this test for your default DataSource

  spot := FDatabaseList.Indexof(Alias);

  if spot < 0 then begin

    if FDataSet.RecordCount = 0 then FDataSet.LoadFromFilewithFields(FileName);

    if not FDataSet.Locate('Alias', Alias, [locaseinsensitive]) then exit;//use main adoconnection

// if comparetext(AdoConnection.ConnectionString,FDataSet.FieldByName(AstaAliasconnectionString).AsString)=0 then exit;

    Ad := TAdoConnection.Create(Self);

    Ad.LoginPrompt := false;

    Ad.Provider:=AdoConnection.Provider;

    Ad.IsolationLevel:=AdoConnection.IsolationLevel;

    Ad.CursorLocation:=AdoConnection.CursorLocation;

    Ad.ConnectOptions:=AdoConnection.ConnectOptions;

    ad.ConnectionString := FDataSet.FieldByName(AstaAliasconnectionString).AsString;

    FDatabaseList.AddObject(Alias, AD);

    result := Ad;

    ad.Connected := True;

  end else result := TComponent(FDataBaseList.Objects[spot]);

end;

 

 



ASTA Overview