Multiple database login


(masterit) #1

hi all,

our server should have one schema and multiple databases with same structure.

now, here is what troubles us:

  • how to dynamically create new connection in server when new database is added? (we have list of databases in one special DB called DBList)
  • how to pull list of available connections on the server from client side? client have simple login form in which he should enter his uname and pword and list of available db connections on server.

we were unable to find any info about this either in documentation or examples.

thank you.


(elenap) #2

Hi,

how to dynamically create new connection in server when new database is added? (we >have list of databases in one special DB called DBList)

To create connection dynamically on the server do the following:

var con: TDAConnection;
...

con:=Schema.ConnectionManager.Connections.Add;
con.ConnectionString:='ConnectionString''; //Look at the format of connection string in Schema Modeler
con.Name:='ConnectionName';
Schema.ConnectionManager.SaveToFile('FileName');
...

Then you will be able to load list of your connections from file:

Schema.ConnectionManager.LoadFromFile('FileName');

how to pull list of available connections on the server from client side? client have >simple login form in which he should enter his uname and pword and list of available >db connections on server.

 If you need to pass necessary information on the server as a variables, pass them as parameters of service methods, whether it is login information or list of connections. 

And look at http://wiki.remobjects.com/wiki/TMultiDbLoginService_Class, maybe you find it useful.


(masterit) #3

Thank you.
Do you have a sample code?
We couldn’t find MultiDB login template for Delphi.


(masterit) #4

We solved it.
GetConnectionNames method of MultiDBLoginService


(Vyacheslav Dulnev) #5
masterit said: We couldn't find MultiDB login template for Delphi.

You are right, this template is missing in new wizard. This issue was logged as 49109.


Using events in Relativity Server to change ConnectionName
(marc hoffman) #6

MultiDBLoginService is really just one (and not necessarily the best) way to do this, anymore. First, your service has of course complete control over what connection to use, and you can change the name in the BeforeAcquireConnection (or similarly named) event.

Now, the second questions is, do you want your client application to choose a connection at will, and of so how. Using MultiDBLoginService is one way to do this, but i would recommend using the LoginEx method in the regular login service, where your client can pass any arbitrary number of parameters to the server (one COULD be ConnectionName=foo). Its seldom that assign the name of the connection from the client is really the right approach. Maybe you want to consider making the connection choose dependent on the login (users Foo.* will use connection A, users Bar.* will use connection B). Or maybe you want to choose the right connection based on some more “abstract” flag (for example to choose via Production and Test database, via UseTestDatabase=YES/NO in the connection string).

these are just ideas and food for thought, of course; how to best handle this depends on your exact needs for your project.

hth,
marc