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

Changing databases at runtime

 Post Reply Post Reply
Author
Halvorsen Thom View Drop Down
New Member
New Member
Avatar

Joined: 06 Feb 2013
Posts: 4
Post Options Post Options   Quote Halvorsen Thom Quote  Post ReplyReply Direct Link To This Post Topic: Changing databases at runtime
    Posted: 22 Jul 2014 at 10:54am
Hello.

Is it possible with RemoteDB for the client to change databases at runtime, i.e. after the server has started?

Thanks.
Thom

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: 22 Jul 2014 at 11:30am
Yes and no. There is no direct way to do that. But there are some workarounds that can be used for that. But I wonder what is your exact need? Note that you can have multiple TRemoteDBModule in your server, for example, http://server/db1 points to one database, http://server/db2 points to another database. So the most common approach our users are doing is to pre-create all possible databases in different addresses, then the client just chooses the URL they want to connect to. Being more flexible than that, i.e., choosing any arbitrary database is still possible, as I said, with some workarounds, but I wonder why it would be needed and if it doesn't decrease security.
Back to Top
Halvorsen Thom View Drop Down
New Member
New Member
Avatar

Joined: 06 Feb 2013
Posts: 4
Post Options Post Options   Quote Halvorsen Thom Quote  Post ReplyReply Direct Link To This Post Posted: 22 Jul 2014 at 12:37pm
Our customers are accountant offices where each client they create in the system database get a physical database created for it. So 20 clients = 20 records in the Clients system database = 20 client databases.

What you are proposing is that you could loop the Client table in the system database and create an address for each record:

http://server/Client1
http://server/Client2
http://server/Client3
etc.

So something like:

FServer := THttpSysServer.Create;
try
  while not ClientDS.Eof do
  begin
    Url := Format('http:/server/%s', [ClientDS.FieldByName('DbName').AsString]);
    FServer.AddModule(TRemoteDBModule.Create(Url, TDBConnectionFactory.Create(
     function: IDBConnection
     begin
       Result := CreateIDBConnection;
     end
    )));
    ClientDS.Next;
  end;
.......

What would you do when a new client database is created? Can you use FServer.AddModule when the server is running? Or does the server need to be stopped?

// Thom

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: 22 Jul 2014 at 12:42pm
Yes, that's how you should do it. I know one of our customers is using that exactly approach. Of course, you should pass the database name to your CreateIDBConnection function so it creates the connection properly (pointing to the correct database). 
You have to stop the server to add modules to the server.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down