Can't select the record if not default connection in Schema

Hi, the Schema has many different connections. I got the error when using “FillWithDASql” that select the records in non-default connection. The table already added into Schema. How to solve it? I’m using Delphi.

Hi,

you can pass ConnectionName to server-side and store it in session for current user.

you can do it via custom method or via IMultiDbLoginService:

  IMultiDbLoginService = interface(IBaseLoginService)
  ['{2C6D5764-01CE-447A-8264-27210B2C7371}']
    function Login(const aUserID: ROUTF8String; const aPassword: ROUTF8String; const aConnectionName: ROUTF8String; out aUserInfo: UserInfo): Boolean;
  end;

usage is simple:

CoMultiDbLoginService.Create(...).Login(...);

Hi,
Sorry that I don’t know where should I put your coding in server side. Where can I found “IMultiDBLoginService”?

Hi,

server-side

  • update login service:
function TLoginService.LoginEx(const aLoginString: String): Boolean;
var
  ls: BaseLoginService_Impl.TLoginString;
  s: string;
begin
  Result := inherited LoginEx(aLoginString);
  if Result then begin
    ls := TLoginString.Create(aLoginString);
    try
      s:= ls.Item['ConnectionName'];
    finally
      ls.Free;
    end;
    if s <> '' then Session['ConnectionName'] := s;
  end;
end;
  • add OnBeforeAcquireConnection event to each DataService like :
procedure TDataService.DataAbstractServiceBeforeAcquireConnection(
  aSender: TObject; var aConnectionName: string);
begin
  if Session['ConnectionName'] <> '' then aConnectionName := Session['ConnectionName'];
end;

client-side

just add it to your login string like:

ConnectionString: String = 'User Id=%s;Password="%s";ConnectionName="%s"';

also update CreateConnectionstring as

function TClientDataModule.CreateConnectionstring(aUser, aPassword: string): string;
begin
  Result := Format(ConnectionString, [aUser, aPassword, 'connection1']);
end;

after this you can pass connection name from client-side.


also you can specify TMultiDbLoginService as the ancestor for your login service. in OnLogin event you can store ConnectionName to Session as before and set it in OnBeforeAcquireConnection event.

after this, you can use on client-side

CoMultiDbLoginService.Create(...).Login(user, pass, `connection1`,..);

Hi,

I read your advise from “Talk”. But I still don’t know where can I found “IMultiDbLoginService”. I can’t found any component that call “IMultiDbLoginService” and “Login Service” in “fServerDataModule”. Would you mind to provide a simple sample for my reference?

Thanks & regards,

Timothy

Hi,

  • Just create a new DataAbstract custom server from the Client and a New Custom DA Server template. Login checkbox should be checked. see more about it at New Project Wizard (Delphi) article.
  • Open LoginService_Impl.pas file and change ancestor from TSimpleLoginService to TMultiDbLoginService:
uses
...
  MultiDbLoginService_Impl; //added

type
  { TLoginService }
  TLoginService = class(TMultiDbLoginService, ILoginService) //changed
...
  • save file and close
  • reopen LoginService_Impl.pas
  • that’s all

Hi,

May I generate “Login Service” manually? Because I created the project and migrated some coding in Server Side.

Thanks & regards,

Timothy

Hi,

yes, of course.

Just add a new Service with MultiDbLoginService or MultiDbLoginServiceV5 ancestor:
Untitled

Hi,

I updated the code as below. Is it correct? And should I remove “TLoginService.LoginServiceLogin”?

Server Side
procedure TLoginService.MultiDbLoginServiceLogin(Sender: TObject; const aUserID,
aPassword, aConnectionName: string; out aUserInfo: UserInfo;
var aLoginSuccessful: Boolean);
begin
CoMultiDbLoginService.Create(‘http://127.0.0.1:8099/bin’).Login(aUserID,aPassword,aConnectionName,aUserInfo);
end;

Client side
function TClientDataModule.CreateConnectionstring(aUser, aPassword: string): string;
begin
Result := Format(ConnectionString, [aUser, aPassword, ‘connection1’]);
end;

How to apply multiple connections of “CreateConnectionstring”? Besides, where should I set “User” and Password"? (Server side & Client side)

Thanks

do you wants to connect to another DA server?

can you describe what you want reach, pls?
if client app should use only one connection all time - this is one case.
if client app should work with different connections after login - this is other case.

Hi,

I only want to connect single DA server at this moment. Client app will work with different connections after login.

Thanks & regards,

Timothy

Hi,

I’ve created a simple testcase:
testcase.zip (63.3 KB)

steps:

  • launch client and server
  • press getConnections
  • select connection in combo box, press login
  • select sql command.
  • press getData
  • logoff
  • select another connection
  • login
  • select another sql command

Note:

  • PCTrade connection contains orders table
  • Simple connection contains orders1 table

Hi,

I tested your simple testcase. It works. But is it possible connect all connections once time without login per time? Because our application need to connect different connections in the same form. I tried to enable “StoreConnected” and “KeepAlive” in “ClientChannel”. But it failed. Any command like as below? Then it can easy to control.

ClientDataModule.RemoteDataAdapter.FillWithDASql(Connection, DAMemDataTable1, ComboBox2.text, nil);

Thanks

Hi,

yes, it is possible. We have solution with heterogeneous connections.
However this solution doesn’t work with DA SQL and FillWithDASql method yet.
logged as #19095 for investigation.

Noted with thanks and wait for your good news about this issue

I tried to change the “TargetURL” to wrong address in “testcase.zip”. But it still can connect successfully without any error. What is the problem come from?

Hi,

can you show an example how do you change TargetUrl, pls ?

Hi,
I directly update the TargetUrl in “TROWinInetHTTPChannel” component before running the application.

Hi,

weird, I’ve set TargetUrl to http://127.0.0.1:8090/bin and I have

---------------------------
Vclapplication
---------------------------
A connection with the server could not be established.
---------------------------
OK   
---------------------------

Have you recompiled client app after changing TargetUrl ?

Hi,
I know the problem. My application is using BPL. ClientDatamodule is keeping in main form and main form link to “runtime package”. If I change the TargetURL, BPL still keeping to using the old TargetURL. I need to recompile all BPL and then the new TargetURL will effective. How to solve this situation?