c# - DNN Database Repository Reuse in Console Application -
i have project based on chris hammond, christoc, module template. have ton of code use access data external database. in repositories change database default whichever need particular object. code looks this:
using (idatacontext ctx = datacontext.instance(mymodulesettingsbase.database_connection_string_key)) { var rep = ctx.getrepository<product>(); products = rep.get().tolist(); }
the default database switched in call .instance().
repositories used custom dnn modules. repository part of solution contains multiple custom modules. when compile , install using extensions part of dnn, works well. in code above, mymodulesettingsbase.database_connection_string_key
found in file mymodulesettingsbase.cs file of module solution. set simple string "productdatabase". in solution base dnn install (not module solution), within web.config file, there value in <connectionstrings>
name="productdatabase"
contains actual connection string. links fine on dnn website.
now writing console application monitoring of site. want access database check values in product table. reuse of repository code have written. in attempt so, added reference mymodules.dll file have 1 copy of base code. works give me access objects , associated repositories when attempt query data fails. when debugging can see fails on line:
using (idatacontext ctx = datacontext.instance(mymodulesettingsbase.database_connection_string_key))
when viewed in debugger, string value mymodulesettingsbase.database_connection_string_key
correctly set "productdatabase" code unable link actual connection string. don't know checking connections string when running console application. attempted put <connectionstrings>
section app.config file didn't trick.
is possible have mymodulesettingsbase.database_connection_string_key
map connection string in external application references dll?
if so, can set value of connection string matches key value stored in mymodulesettingsbase.database_connection_string_key
?
i faced similar problem 3 months ago, @ time want use dnn core libraries in console application failed.
i placed queries in dnn official forum website , got valid response wes tatters (dnn mvp).
here post link: reference url
as requirement of monitoring, suggest create dnn schedule application. can schedule within dnn (host->advancedsettings->schedule), point can use repositories (dnn libraries) in schedule application.
i hope solved problem. let me know if have questions.
Comments
Post a Comment