Developer forum

Forum » Development » IDatabaseConnectionProvider implementation is not used in Repositories/Index, overwriten by GlobalSettings connection string

IDatabaseConnectionProvider implementation is not used in Repositories/Index, overwriten by GlobalSettings connection string

Torben Bak Jensen
Reply

Hi, 

We have implemented IDatabaseConnectionProvider class, with the intention to tell dyamicweb which connection string to use. Everyting works great, except for one place (or we have found it not to work in one place so far), which is Indexing. If I go in /Admin > Managment Center > Repositories <Repository> name and attempt to manage the Index Repository, it is very clear that connection string from GlobalSettings is in use. It connects to the database using GlobalSettings connection (throws an error if there isn't a valid one) and Indexes using data from that database. Needless to say we are expecting it to use database connection specified in implementation of IDatabaseConnectionProvider , as it is used in other places, like front end displaing products from the correct database (if we specify a shop to use products from a database instead Index).

Placing a connecion string back in GlobalSettings fixes the problem, and it works again.

Is there a reason why implementation of IDatabaseConnectionProvider is not used in Repository/Index? Is there a way to make sure it is used there?

Thank you.


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Torben

The indexing is running inside our taskhandler which is running in a seperate thread and therefore do not have access to some things in DW, i.e. httpcontext whcich is required in some scenarios.

Therefore the connection string comes from the taskmanager context and is set when DW starts up - this is what we do.

TaskManager.Context = New Diagnostics.Tasks.Context() From
                                                                   {
                                                                      {"Database.ConnectionString", Database.ConnectionString}
                                                                   }

Of course we should look at the provider in this case - but you can just overwrite the context with your own provider.

BR Nicolai

 
Torben Bak Jensen
Reply

Hi Nicolai,

Thanks for a quick reply!

That makes sense. I will try your solution, as the "hack" we went to for now was running a method during application startup, which reads both web config and globalsettings, replacing Database part of the XML with values from WebConfig's appSettings. 

 

 

You must be logged in to post in the forum