Using llblgen with multiple database connections

Posts   
 
    
Tommygun
User
Posts: 4
Joined: 05-Apr-2007
# Posted on: 05-Apr-2007 01:55:32   

Hi Everyone,

I need to be able to access multiple database within a single winforms app using llblgen. To be specific I have a data layer that I need to be able to connect to 2 or 3 database instances that have the same schema.

I am hoping to write code like.

Database1.Entities.Customer... Database2.Entities.Customer...

I can’t see any obvious way that this is supported.

Any ideas would be very much appreciated.

Regards,

Tom Sedlacek Network Software Analyst Dmg Radio Australia

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Apr-2007 04:54:01   

There're some ways you can achieve that. Review this suggestion: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5833

David Elizondo | LLBLGen Support Team
Tommygun
User
Posts: 4
Joined: 05-Apr-2007
# Posted on: 05-Apr-2007 05:03:43   

Hi There,

Thanks for the response.

Currently my DataAccess layer is written using the self-service code.

I still don't clearly understand how I can create two instances of this DAL and point them to a separate database each.

From my understanding when I do something like :

CustomerEntityCollection List = new CustomerEntityCollection(); List.GetMulti(null);

The above code will get the data from where ever the "Main.ConnectionString" points two.

Could you give me a little more help?

Thanks heaps.

Regards,

Tom Sedlacek Network Software Analyst Dmg Radio Australia

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Apr-2007 11:53:07   

Provided you have same databases (with the same catalog name but on different servers) You can change the connection string at runtime. The following is copied from the LLBLGen Pro manual:

Connection strings The DbUtils class lets you set the global connection string to use for every connection to the database. This setting overrides the connection string read from the appSettings section in the .config file. Once the setting is set, every connection to the database uses the set connection string. You set the connection string to use at runtime using the following code: // C# DbUtils.ActualConnectionString = "Datasource=myserver;...."; ' VB.NET DbUtils.ActualConnectionString = "Datasource=myserver;...." If you want to make the application use the connection string defined in the config file again, simply set the ActualConnectionString property to string.Empty.

Tommygun
User
Posts: 4
Joined: 05-Apr-2007
# Posted on: 05-Apr-2007 12:20:11   

Hi there,

Thanks for your continuing help on this issue!!

I get how I can change the connection string using the DB utils class. What I don't get is how I can have multiple instances of a database layer activated at the one time.

As soon as I change the connection string using the DB utils class I can get data from another database, but then to get data from the first database do I need to change the connection string again? I need to be able to access multiple database at the same time, possible from different threads.

I need to have two instances of the data access layer so I can do so something like.

DB1.DbUtils.ActualConnectionString = “Datasource=server1”; DB2.DbUtils.ActualConnectionString = “Datasource=server2”;

When I add my data access layer reference to a project I can’t really make multiple instances of it. Or Can I? From my understanding there is no way of making an instance of the DbUtils class, all of its properties and methods are static.

Sorry if I am miss understanding something fundamental about how all this works. Any help you give me would be much appreciated.

Regards,

Tom Sedlacek Network Software Analyst Dmg Radio Australia

Tommygun
User
Posts: 4
Joined: 05-Apr-2007
# Posted on: 05-Apr-2007 12:44:46   

Hi Everyone,

Just a bit of extra info. Obviously this easy to do using the adapter templates, because the data adapters take a database connection string. So I can create an adaptor for each of the database without an issues.

I am really wondering if there is some way to support multiple database instances using the self service templates?

I have already written a lot of code for this project using my current DAL and the requirement to access multiple database has just come up, had I known sooner I would have used adapter, but if possible I don't want to change from self service now.

Thanks again for all the help,

Regards,

Tom Sedlacek Network software Analyst Dmg Radio Australia

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Apr-2007 12:54:56   

Adapter is the appropriate model to use in your scenario. Since the Adapter has the separation between the DBSpecific code/dll (DataAccessAdapter) and the DBGeneric code/system objects (entityClasses...etc). Otherwise you would have to use multiple SelfServicing projects.