Using/changing multiple databases in 1 project

Posts   
 
    
dmenp
User
Posts: 2
Joined: 15-Dec-2014
# Posted on: 16-Dec-2014 09:30:09   

Hello,

I have an webproject with an LLBLGen project in.

The problem is that I have to use different databases, depending on who is logging in on the website.

All the databases have the same structure, just the name is different.

I want to know if there is a solution so I can use 1 LLBLGen project but change the database according to the person who is logging in i on the website.

Thank you, DMenP

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Dec-2014 08:14:03   

DataAccessAdapter has a ctor overload that receives the connection string. You can set that connectionString to the one you want to use depending on some action.

At login:

switch(user.Region)
{
     case "A":
          myGlobalCnnStr = "...dbA...";
          break;

     case "B":
          myGlobalCnnStr = "...dbB...";
          break;

     ...
}

Then in your subsequent DataAccessAdapter instantiation:

using (var adapter = new DataAccessAdapter(myGlobalCnnStr);
{
     ...
}

Another way to do this is to use CatalogNameOverwrites. Example: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=22277&StartAtMessage=0&#125728

You could use a custom adapter factory pattern to return the correct one each time you need it.

David Elizondo | LLBLGen Support Team
dmenp
User
Posts: 2
Joined: 15-Dec-2014
# Posted on: 18-Dec-2014 09:08:20   

Thank you,

I will have look!