0
votes

I want to access another database for my dnn project not the one which is configured for dnn during installation.

I can able to access the connection string if I add one key/value in appsettings in dnn configured web config file.

Is this correct way? or Do I need to add new config file for adding connection string ? If so how can i access connection string in dnn C# compiled modules

1
In my point of view, I believe that the best practice consist to add a key/value in the appsettings section of the web.config. You also could manage the setting of this connection string in a dnn module: in the module settings for example. It depends of what you need exactly. - Stéphane TETARD

1 Answers

1
votes

The web.config approach would likely be the best way, but if you're installing the module remotely you'll have to remember to setup the web.config file, or use the XMLMerge functionality that is available in DNN. I've got an example for adding information to the web.config file in my DNNSimpleArticle module https://dnnsimplearticle.codeplex.com/SourceControl/latest#cs/dnnsimplearticle.dnn look at the config section

   <component type="Config">
     <config>
       <configFile>web.config</configFile>
       <install>
         <configuration>
           <nodes>
             <node path="/configuration/dotnetnuke/sitemap/providers" action="update" key="name" collision="overwrite">
               <add name="DNNSimpleArticleSiteMapProvider" type="Christoc.Modules.dnnsimplearticle.Providers.Sitemap.Sitemap, DNNSimpleArticle" providerPath="~\DesktopModules\dnnsimplearticle\Providers\Sitemap\" />
             </node>
           </nodes>
         </configuration>
       </install>
       <uninstall>
         <configuration>
           <nodes />
         </configuration>
       </uninstall>
     </config>
   </component>

That will add a new sitemap provider,but you could tweak for connection strings instead.

Two other options.

Hard code the connection string in your module, not idea from flexibility perspective.

Create a module setting and store the connection string there. That will allow you to at least change it through the UI in DNN.