Multiple database connections

Posts   
 
    
wvnoort
User
Posts: 96
Joined: 06-Jan-2005
# Posted on: 11-Jan-2005 10:09:20   

Hi all, I need some directions on the use of multiple database connections.

  1. The application needs to support multiple sets of data, implemented as several SQL server database with the same schema. The end user must be able to swich (from the entry-screen of the application) to the required database. Some of the entities are stored in a separate database to share some parts over all sets of data.

I would like to configure the list of all available databases and the database designated for the shared parts using the configurations files.

  1. I noticed, that using the supplied templates, the connection string in the app.config contains human-readable username and password. I think these should be encrypted.

Can any one give me some hints or examples on these subjects?

Thanks in advance Wouter

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 11-Jan-2005 11:01:54   

Best way to deal with this is using Adapter, and then pass in the connection string to use in the DataAccessAdapter constructor. Also, as the schema is the same on all databases, you can use a single codebase, and simply overwrite the catalog name per call, also through the DataAccessAdapter constructor. See the DataAccessAdapter functionality in the docs: Using the generated code / Adapter / DataAccessAdapter functionality

Frans Bouma | Lead developer LLBLGen Pro
wvnoort
User
Posts: 96
Joined: 06-Jan-2005
# Posted on: 11-Jan-2005 12:12:53   

Frans,

As I understand what you suggest:

I need to create my own keys in the config file (where the username and password are encrypted) and then I need the dataAccessAdapter get the values from the config file, decrypt it, and construct the connectionstring and pass it to the DataAccessAdapter.

Is that correct?

Now a variation on this theme: The DataAccessAdapter is database specific. I also want to switch dynamically between Oracle and Sql Server without having to use 'if() ... else ..' construction through all code.

Wouter

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 11-Jan-2005 13:08:52   

wvnoort wrote:

Frans,

As I understand what you suggest:

I need to create my own keys in the config file (where the username and password are encrypted) and then I need the dataAccessAdapter get the values from the config file, decrypt it, and construct the connectionstring and pass it to the DataAccessAdapter.

Is that correct?

No, you can store the connection strings anywhere you like, as when you pass in a connection string into the constructor, the connection string is not read from the config file, but the one passed in is used.

Now a variation on this theme: The DataAccessAdapter is database specific. I also want to switch dynamically between Oracle and Sql Server without having to use 'if() ... else ..' construction through all code. Wouter

DataAccessAdapter implements IDataAccessAdapter. So your code can program against the interface and you have to write a small factory which creates either an Oracle DataAccessAdapter or an SqlServer DataAccessAdapter (i.e.: instantiates a dataaccessadapter instance from the oracle database specific project or instantiates a dataaccessadapter instance from the sqlserver database specific project). You have to keep the columns the same between oracle and sqlserver and you have to use compatible types (i.e.: don't use GUID's on sqlserver or bit fields, as these are not supported on oracle).

A dataaccessadapter factory class is a good idea anyway, as you need to obtain the connection string and decrypt it as well.

Frans Bouma | Lead developer LLBLGen Pro