Dynamic Catalog Name overwriting?

Posts   
 
    
astrnad
User
Posts: 30
Joined: 23-Jul-2007
# Posted on: 02-Mar-2010 15:31:46   

Hello,

I have a rather general question which i could not find an answer in the documentation to:

I have made a utility component which i use in various projects, this component uses some tables to store and retrieve its data. Initially, i made a database to host those tables and create the component, but now i want to use the component and host the necessary tables in the databases (multiple) which are used by the corresponding projects. Problem is: the catalog name is hardcoded in the components DAL, but the tables are in the databases of the projects the component is used in. To access the tables in a project from within the component, i use the DbHelper.ActualConnectionString property to show the component the way to the database. This brings me to the problem that the database name doesn't match the name of the catalog which was used to create the component, and i can't use a simple name overwrite because there are multiple projects involved. Is there a way to tell a project to overwrite the catalog name with the one from the connection string at runtime?

Best regards, Alex

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 02-Mar-2010 21:19:06   

Sorry, I'm not sure I follow when you say

and i can't use a simple name overwrite because there are multiple projects involved.

Could you explain further...?

Thanks

Matt

astrnad
User
Posts: 30
Joined: 23-Jul-2007
# Posted on: 02-Mar-2010 22:36:08   

MTrinder wrote:

Sorry, I'm not sure I follow when you say

and i can't use a simple name overwrite because there are multiple projects involved.

Could you explain further...?

Thanks

Matt

I mean that every project involved has its own database with its own DAL and its own catalog name. Within these catalogs there are the tables which the component uses, they are equally named across all projects. So because there are multiple connection strings to the databases for each project, i can't statically rename the catalog names on each project, because for the project DAL, the catalog name hasn't changed since creation, but for the component it has. I would need something to tell the component DAL to use the catalog name of the project it is currently used in. Does that make any sense?

Best regards, Alex

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 03-Mar-2010 10:21:41   

I'm not sure I understand you, sorry cry

For every running application you can have a config file, and there you can overrite more than one catalog name.

I mean that every project involved has its own database with its own DAL and its own catalog name. Within these catalogs there are the tables which the component uses, they are equally named across all projects.

OK, so that's one application using your component, no problem so far, using the Catalog name overwriting should handle this correctly. So if your component was built against a catalog called "car", and now it's operating under a catalog named Audi, then the following is suffucuent for her.

<sqlServerCatalogNameOverwrites>
    <add key="car" value="Audi" />
</sqlServerCatalogNameOverwrites>

So because there are multiple connection strings to the databases for each project, i can't statically rename the catalog names on each project,

I can't understand this phrase, are you speaking about multiple usages of the component in the same application, to different catalogs. Or are you speaking about different components used in the same application all are targeting the same catalog. But each one of these components was built against a different catalog name.

Example: Application "A" uses component "B" and component "C" "A" uses caalog "Audi" "B" was buolt against catalog "car" "C" was built against catalog "auto"

Since Audi is the current catalog name, then the following should solve this situation:

<sqlServerCatalogNameOverwrites>
    <add key="car" value="Audi" />
    <add key="auto" value="Audi" />
</sqlServerCatalogNameOverwrites>
astrnad
User
Posts: 30
Joined: 23-Jul-2007
# Posted on: 03-Mar-2010 10:40:11   

Walaa wrote:

I'm not sure I understand you, sorry cry

Walaa wrote:

I can't understand this phrase, are you speaking about multiple usages of the component in the same application, to different catalogs.

Yes, that's where it's going at - One application, multiple projects, one component being used across these projects.

I hope i can clarify this a bit by a practical example simple_smile

Lets say i have an application, which consists of 3 different projects, project A, project B and project C (all being DLLs when they get compiled). Project A connects to database DbA, project B to database DbB and project C to database DbC, every project uses its own LLBL generated DAL.

Now, a monitoring project, call it component M, comes into play. It is supposed to do monitoring and store status in its own tables, called T1 and T2, but as being a component, it's not meant to have its own database, but rely on its tables T1 and T2 being present in the database the current project uses.

For our example: A uses M, B uses M and C uses M, therefor, T1 and T2 have to be present in DbA, DbB and DbC.

Problem is: T1 and T2 where originally in database DbM, so on generating the DAL for M, DbM is hardcoded onto the DAL. So far so good, if M was only used in A, i would make a rename from DbM to DbA. But as M is used in A, B and C, i can't make a rename from DbM to DbA, DbM to DbB and DbM to DbC, can i? If i was a piece of software, i'd find that rather confusing wink (As hopefully this post isn't wink )

Question is: Is there some why to use the catalog renaming in code somehow? Can i maybe tell M to use the catalog from the connection string of the project we're currently in (that being A, B or C)?

Best regards, Alex

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 03-Mar-2010 11:04:51   

Question is: Is there some why to use the catalog renaming in code somehow? Can i maybe tell M to use the catalog from the connection string of the project we're currently in (that being A, B or C)?

<sqlServerCatalogNameOverwrites>
    <add key="DbM" value="" />
</sqlServerCatalogNameOverwrites>

An empty name as shown in the config. above, would force it to use the one in the current connection string simple_smile

astrnad
User
Posts: 30
Joined: 23-Jul-2007
# Posted on: 03-Mar-2010 11:35:02   

Walaa wrote:

<sqlServerCatalogNameOverwrites>
    <add key="DbM" value="" />
</sqlServerCatalogNameOverwrites>

An empty name as shown in the config. above, would force it to use the one in the current connection string simple_smile

Walaa, you're a genius - works like a charm!

Best regards, Alex