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.
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;
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.
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.
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.