DA - MultiDbLoginServiceV5 - What determines on client which connection is to be used

After successfully logging into the Login Service using MultiDbLoginServiceV5, what on the client side determines which connection is to be used.

I would myself answer that it would be the connection that was logged in as.

But what I am getting is the default data connection on the server.

Does the session contain the designated connection?
How can we on the client determine the active current connection that we are about to connect to?

In our case, we first need to connect to a System database for user access rights and then to our Data database. We are able to log onto both successfully.

I would have thought that the second connection login to the Data database would remain as the designated connection.

Thanks.
Bill Brittain

Hi,

MultiDbLoginServiceV5 service just passes aConnectionName to OnLogin event.

our code doesn’t put ConnectionName into session, but you can do it manually like

Session.Values['ConnectionName'] := aConnectionName;

in DataService.OnBeforeAcquireConnection, you can set connection name like

procedure TOrdersService.DataAbstractServiceBeforeAcquireConnection(
  aSender: TObject; var aConnectionName: string);
begin
  // Reads the connection name from the main form.
  aConnectionName := Session.Values['ConnectionName'];
end;

You can get default connection name with IMultiDbLoginServiceV5.GetDefaultConnectionName method.

if you want to return active current connection, you can write custom method and return TBaseDataAbstractService.ConnectionName

Evgeny,
Thank you for the reply. It was the BeforeAcquireConnection on the DataService that we were not implementing. I have it working in a test mode. I will need to adjust how we create the connections list when the server is started up so that the naming will become automatic by the server from our system database.

Now, on that thought. Our users normally login and are shown their specified company databases. What would you suggest as to how to set the connection name for the session AFTER a login?

Sometimes, our users will have access to five or six different company databases. All have the same schema but they are different locations for the same company. All the databases are located on the same server.

I am thinking a new service method where we would pass the session id and connection name to the server where the method would update the session[connectionName] with the specified connection name. Then the Acquire would pickup the new connection on the next data connection.

Bill Brittain

Hi,

You can use code like

procedure TLoginService.MultiDbLoginServiceLogin(Sender: TObject; const aUserID,
  aPassword, aConnectionName: UTF8String; out aUserInfo: UserInfo;
  var aLoginSuccessful: Boolean);
begin
...
  loginReader := Schema.NewDataset(Connection, 'FindEmployee', ['UserName', 'Password'], [aUserID, aPassword]);
  jobTitle := '';
  try
    if (loginReader.IsEmpty) then begin
      DestroySession;
      aLoginSuccessful := false;
    end
    else begin
   ...
      // Saves information in the current session for the other services to use
      Session['EmployeeID'] := aLoginInfo.EmployeeID;
      Session['JobType'] := aLoginInfo.Job_Type;

      Session.Values['ConnectionName'] := aConnectionName;
      aLoginSuccessful := true;
    end

end;

On the topic of changing the session AFTER a login has occurred, we have determined after reading thru some posts to change our login slightly to allow for a connection name to be passed or not.

If the login is the first time, ( our server default database is the System database ), no connection is passed. The default connection is therefore System.

If the user has already logged in, we lookup the active company databases from System that are associated with that user ( UserCompanies ) and use that list for the needed connection.

We then silently log in ( no login screen ) with the user credentials and connection name for the company database. The session is set ( Session[‘ConnectionName’] and we are set for that user and that database connection.

Seems to be working for now but we will see what kind of problems we have not foreseen.

Our tables are Companies, Users, UserCompanies, and UserCompanyAccessRights.

Bill Brittain

Hi,

You can pass allowed connection names to client-side in UserInfo struct or his descendant.
Client-side can call custom service method and set required connection.

On user sessions, are the Sessions maintained the same, if the Session is required for the service or not.

In other words, does the session created for a user on login, stay maintained for that user even if the session is not required.

I am getting some odd things happening when I turn the RequiresSession on and off.

We were doing this when doing the Design time for pulling schemas for tables, but now I am wondering about the session management overall.

Hi,

Session is created manually with CreateSession method or session is accessed via Session property.

when it has off value, this service can be accessed w/o login. this is required only for LoginService.

you may avoid to touch RequiresSession soon. We have added a mechanism that allows to receive schemas for tables w/o login.

note: this isn’t implemented on Delphi side yet.


EDIT: this feature will be in .1585.