Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

IDBConnection multiple connections

 Post Reply Post Reply
Author
Eduardo Elias View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 May 2014
Posts: 233
Post Options Post Options   Quote Eduardo Elias Quote  Post ReplyReply Direct Link To This Post Topic: IDBConnection multiple connections
    Posted: 15 Jul 2014 at 10:27am
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.
Back to Top
Eduardo Elias View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 May 2014
Posts: 233
Post Options Post Options   Quote Eduardo Elias Quote  Post ReplyReply Direct Link To This Post Posted: 15 Jul 2014 at 12:38pm
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?
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2432
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 15 Jul 2014 at 4:02pm
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.
Back to Top
Eduardo Elias View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 May 2014
Posts: 233
Post Options Post Options   Quote Eduardo Elias Quote  Post ReplyReply Direct Link To This Post Posted: 15 Jul 2014 at 7:37pm
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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down