Base On Login User to select the Database Connection

Hi,

I want to base on logined user to select the database connection.

As I know that the service is pooling, what is suggested way to achieve this?

For example : if it is public function i can setup the connection before data call ?
how about TDamemtable access the export data or stored procedure?

is it any way to setup the DB connection base on user ?

any suggestion?

Joe

Hi,

you can use MultiDbLoginServiceV5 service as an ancestor for your Login service:

it contains these methods:

    function Login(const aUserID: ROUTF8String; const aPassword: ROUTF8String; const aConnectionName: ROUTF8String; out aUserInfo: UserInfo): Boolean;
    function GetConnectionNames: StringArray;
    function GetDefaultConnectionName: ROUTF8String;

so you can get list of connections and pass required connection name in the Login method

Yep, After login, if I required other data service , will it keep the same database connection?

After Login, I will consume other Dataservices, is it ensure the correct database connecton or keep the connection for it?
As I know all service call or export database it is pooling , if user A use connection A, User B use Connection B, however User C i want to use back Connection A. For such case , what is the suggested way to achieve ?

joe

Hi,

You can create a custom method like SetConnectionName or create custom method like MyGetData that can contain connection name parameter. Implementation of MyGetData can be: set connection name and call default GetData method

Take a example:

Server Side

DataService 1 :
Procedure SetConnectionA;
Procedure SetConnectionB;

At Client Side:

Dataservice 1. SetConnectionA;

Then TDaememtable.open, it is separate function call , can it ensure same incident of the DataService1?

As from my understand, different function call to DataService1 , cannot confirm it is same incident as you consume before.

Am i Correct?

joe

Hi,

it depends on your implementation of SetConnectionA.
I can suggest to store connection name to Session and restore it in events of DataService like

procedure TDataService.DataAbstractServiceActivate(const aClientID: TGUID;
  aSession: TROSession; const aMessage: IROMessage);
begin
  ConnectionName := Session['connectionname'];
end;

Great let me try.

joe