IDBConnection multiple connections

I am starting to integrate the RemoteDB in my application.


I am using ElevateDB as the back database server.

I have always 2 databases opened, one for configuration in general, and the other with the application data.

Reading the help file i see this comment:

"Note that in client you don't need (and shouldn't) create both
TRemoteDBDatabase and IDBConnection for each manager you use. The code above is
just an explanation about how to create those classes. In a real client
application, you would create the IDBConnection interface and share it among
different TObjectManager instances."

IN my code I have a adapter where I create a TRemoteDBDatabase and the correspondent IDBConnection.

I create 2 instances of this adapter, since I have 2 database connections.

Is it a problem? 

I am also working this way since I will eventually have a threaded application then I commonly separate completely database code for each thread.

Following my question above I used the RemoteDBServer as base for my server, and changed this:


function TFormMain.CreateElevateDBConnection: TEDBDatabase;
begin
  result := TEDBDatabase.Create(nil);
end;

function TFormMain.CreateIDBConnection: IDBConnection;
begin
  Result := TElevateDBConnectionAdapter.Create(CreateElevateDBConnection, true);
end;

procedure TFormMain.StartServer;
begin
  CreateIDBConnection.Connect;

  FServer := THttpSysServer.Create;
  try
    FServer.AddModule(TRemoteDBModule.Create(edtServerUrl.Text, TDBConnectionFactory.Create(
        function: IDBConnection
        begin
          Result := CreateIDBConnection;
        end
    )));
    FServer.Start;
  except
    FreeAndNil(FServer);
    raise;
  end;
end;

I see now there are 2 situations:

- on client side, my application will create at least 2 connections. (this is my previous question for IDBConnection)

- on the server side I don't know what to do. Since when creating the ElevateDB I need to specify the database that I need to use.

I have 2 databases on ElevateDB: Global and Standard. I want both, always. 

What I have to do? register 2 TRemoteDBModule modules for each ElevateDB database that I have, then I create each TEDBDatabase according the need?

This means that I will have a URL like this:

'http://localhost:2001/nahar/global'   for my global module connection
'http://localhost:2001/nahar/standard' for my standard module connection

Is this all correct?

About your first question: yes, you can use two connections. The warning in documentation is just to avoid misleading about the code example. The IDBConnection is the equivalent of the old "TDatabase" and analog (like TADOConnection, TFDConnection, TSQLConnection, etc.). You don't create one database/connection for each dataset you open. But of course you can have more than one in your application.


About your second question, also yes, that's the way you should use it.

Just a small remark about your server code: you don't need the first line with "CreateIDBConnection.Connect", unless you are doing it to check database connection? Because that line will just connect to database and then destroy the IDBConnection anyway.

Wagner,


I made the changes and I am trully AMAZED with the simplicity to make this happen!!!!

Now my software can connect to the ElevateDB via RemoteDB and worked very well. 

The 2 connections are working correctly and recognized both databases.

Thank you