Multi connection on multi database

Posts   
 
    
EtienneKep
User
Posts: 6
Joined: 13-Mar-2014
# Posted on: 13-Mar-2014 11:39:47   

Hello,

We are actually looking for an alternative to Entity Framework and found llblGen. We need to make a model which is connecting to multi database on multi sql server (multi connection string).

Is it possible ? If yes, could we using the selfservicing mode ? (We need to use lazy loading).

Thanks in advance, Kind regards, Etienne.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 13-Mar-2014 11:57:08   

EtienneKep wrote:

Hello,

We are actually looking for an alternative to Entity Framework and found llblGen. We need to make a model which is connecting to multi database on multi sql server (multi connection string).

Is it possible ?

With adapter this is possible. You can issue the connection string per-call and issue catalog names (and schema names) per call, so you can have 1 model which is present on multiple servers in multiple catalogs and access the correct one per call.

If yes, could we using the selfservicing mode ? (We need to use lazy loading).

Thanks in advance, Kind regards, Etienne.

Unfortunately not (it can be done in some situations, but requires additional modifications and is not supported by us). The thing is that selfservicing is doing things 'for you' like when doing lazy loading, and it then will pull the connection string to use from its own variable which is static. If you want to control to which server it connects, it has to know where to get that information, but with lazy loading you will issue that at random moments, so it's not possible to provide that information when doing lazy loading. It is key to the concept of lazy loading that there's no information necessary to provide to connect and obtain the data, as it would otherwise not be lazy loading wink

Are you sure you absolutely need lazy loading? in general it often is required at first but after a while people will realize it's actually a bit of a burden, because it will often lead to performance problems due to the retrieval of data without knowing it.

Frans Bouma | Lead developer LLBLGen Pro
EtienneKep
User
Posts: 6
Joined: 13-Mar-2014
# Posted on: 13-Mar-2014 12:21:55   

Hello,

Thanks, For the first part, here is a code sample which failed :


EntityCollection trades = new EntityCollection(new TradeEntityFactory());
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.TradeEntity);
prefetchPath.Add(TradeEntity.PrefetchPathCustomer);
IRelationPredicateBucket filter = new RelationPredicateBucket(); 

// The connection string of "Trade" database
// "Customer" table is in a different database (and different server)
DataAccessAdapterBase adapter = new DataAccessAdapter("data source=xxxx;initial catalog=master;integrated security=SSPI;persist security info=False;packet size=4096");

adapter.FetchEntityCollection(trades, filter, prefetchPath); 
//  ==> When fetching entity, it failed because it cannot reach the "Customer" table

How can I make this loading with 2 connections string ?

For the lazy loading, it help to improve performance in GUI, when displaying details on data for example. If we have thousand source lines and want to display details only for 2 lines we don't want to load details for all source lines. With an adapter we will need to load manually this data. It could be done, but it's easier to use lazy loading.

Thanks, Regards, Etienne.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 13-Mar-2014 12:35:30   

EtienneKep wrote:

Hello,

Thanks, For the first part, here is a code sample which failed :


EntityCollection trades = new EntityCollection(new TradeEntityFactory());
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.TradeEntity);
prefetchPath.Add(TradeEntity.PrefetchPathCustomer);
IRelationPredicateBucket filter = new RelationPredicateBucket(); 

// The connection string of "Trade" database
// "Customer" table is in a different database (and different server)
DataAccessAdapterBase adapter = new DataAccessAdapter("data source=xxxx;initial catalog=master;integrated security=SSPI;persist security info=False;packet size=4096");

adapter.FetchEntityCollection(trades, filter, prefetchPath); 
//  ==> When fetching entity, it failed because it cannot reach the "Customer" table

How can I make this loading with 2 connections string ?

I need more info in how your model is spread across catalogs in your project in the designer and in the databases. A connection can only be created to one server at a time. The names of the databases in that server can be rewritten in the query. So you can have catalog A, B and C in your project in the designer (you can add multiple catalogs there) and at runtime you have on server S catalog D, E and F. You can then specify overwrites so A->D, B -> E and C->F, see: http://www.llblgen.com/documentation/4.1/LLBLGen%20Pro%20RTF/hh_goto.htm#Using%20the%20generated%20code/Adapter/gencode_dataaccessadapter_adapter.htm#Catalogspecificpersistenceinfo

If at runtime it turns out that catalog D is not on S but on on another server T, you can't connect to that catalog when you connect to S. I honestly don't think it is that disconnected, so please provide more information about how the model looks like in practice and when the names of the catalogs change (of they change) from the catalogs used in the project in the designer.

(btw that code snippet uses syntax which is a bit outdated, for fetching queries, please look at QUeryspec or linq)

For the lazy loading, it help to improve performance in GUI, when displaying details on data for example. If we have thousand source lines and want to display details only for 2 lines we don't want to load details for all source lines. With an adapter we will need to load manually this data. It could be done, but it's easier to use lazy loading.

Ok, good point. That's however not supported at this point.

Frans Bouma | Lead developer LLBLGen Pro
EtienneKep
User
Posts: 6
Joined: 13-Mar-2014
# Posted on: 13-Mar-2014 13:39:27   

Server 1 ==> DataBase 1 --> Table 1 --> Table 2 --> Table 3 ==> DataBase 2 --> Table 4 --> Table 5 --> Table 6

Server 2 ==> DataBase A --> Table a --> Table b --> Table c ==> DataBase B --> Table d --> Table e --> Table f

We wan't to make a model with a link between : - Table 1 (Server 1 / DataBase 1) - Table b (Server 2 / DataBase A)

I understand that we can't load at the same time the data from Table 1 and Table b and we need to use 2 Adapter (1 for Server 1 and 1 for Server 2) ?

But if we make a link between - Table 1 (Server 1 / DataBase 1) - Table 4 (Server 1 / DataBase 2) We can load data using only 1 adapter (and 1 connection string) ?

Is that right ?

Thanks, Regards, Etienne.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 13-Mar-2014 17:57:28   

But if we make a link between

What do you mean by making a link? Are you talking about a "Linked Server"?

EtienneKep
User
Posts: 6
Joined: 13-Mar-2014
# Posted on: 14-Mar-2014 09:09:57   

No, I mean making an association between the two tables

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 14-Mar-2014 11:04:35   

That's correct, an association / relationship between table1 and table4 will work with 1 adapter.

The association between table 1 and table b is not recommended, as the association is also used to create joins which obviously won't work if the tables are on separate servers. So you then need separate models, one for server 1 and one for server 2. I recon you use this setup to vertically partition your model across servers?

Frans Bouma | Lead developer LLBLGen Pro
EtienneKep
User
Posts: 6
Joined: 13-Mar-2014
# Posted on: 14-Mar-2014 11:46:53   

I just wan't to know the limitation, we actually make replication of one database from a server to another to avoid this problem. Thanks for your answers simple_smile