DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Access external DBs on module install/upgrade

Sort:
You are not authorized to post a reply.





Growing Member





    Let's say we need all our application data (tables, storeds, ...) to be stored on a different database than the base DNN Sqlserver database. Will the module install feature provide any means for running the sql files on a different database?

    The basic goal here would be to keep all DNN stuff in the DNN database and all application stuff in a separate database. But I don't want to loose the option of being able to install a new version of the module that will execute some SQL to update tables, sps, ...

    Is that possible?

    Vicenç Masanas
    Disgrafic ITec SL Banyoles - Spain





    New Around Here





      To use a different SQL database that the DNN database, just add a new Key under appSettings in your web.config file, giving this connection string a new name. Then you can connect to this second database by extracting the new connection string.

      I have used this technique to separate non-DNN data from the organization-specific data.

      Hope this helps.





      Veteran Member





        Thanks for the very helpful answer.

        It would be nice to see some code examples, particularly running SQL scripts on the external database during install or uninstall. It would be even nicer to see something that could be added to the dnndocs website!

        Joe Craig
        DNN MVP
        Patapsco Research Group





        Growing Member





          Hans, thanks for the reply, but that's what not I was asking actually. I know we can do this and we already do this.

          My question again is: when we install/update the module, is there a way to make the installer RUN the sql scripts against the different database or it always goes on the DNN database?

          Vicenç Masanas
          Disgrafic ITec SL Banyoles - Spain





          Advanced Member





            It always runs against the DNN database. You could use IUpgradeable to run other scripts, or use linked databases to run scripts on the other database from the DNN database.
            DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase





            Growing Member





              Would that be an interesting feature to add, or it's just me that finds this interesting?

              Vicenç Masanas
              Disgrafic ITec SL Banyoles - Spain





              New Around Here





                I believe that in the script all you would need to add is a USE Database directive referening the name of your database name maintained in the web.config file.






                Veteran Member





                  Posted By Brian Dukes on 09 Aug 2019 11:58 AM
                  It always runs against the DNN database. You could use IUpgradeable to run other scripts, or use linked databases to run scripts on the other database from the DNN database.

                  Yep... What he said ^^^

                  Whenever we need data to live in another data source, we use DNN's built-in functionality to install normally, then have a process migrate it after.  For example, we do this a lot with custom modules that have PII.  






                  Veteran Member





                    Posted By HansZ on 09 Aug 2019 01:03 PM

                    I believe that in the script all you would need to add is a USE Database directive referening the name of your database name maintained in the web.config file.

                    I haven't tried that specifically recently, but in my case, we're often using a different data source altogether (e.g., other server, other DB server, etc.) and it requires an additional data connection string instead of USE.  

                    Oh, and to address an earlier comment... I wouldn't ever suggest putting any connection string details in the AppSettings.  You should use the connectionStrings section in the web.config instead.  :) 






                    Advanced Member





                      I use Entity Framework in those situations, it migrates your database schema on the fly as soon as it notices it does not match your model. I love it!
                      You are not authorized to post a reply.

                      These Forums are dedicated to the discussion of DNN Platform.

                      For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

                      1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
                      2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
                      3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
                      4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
                      5. No Flaming or Trolling.
                      6. No Profanity, Racism, or Prejudice.
                      7. Site Moderators have the final word on approving / removing a thread or post or comment.
                      8. English language posting only, please.

                      Would you like to help us?

                      Awesome! Simply post in the forums using the link below and we'll get you started.

                      Get Involved