DNN Forums

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

Developing a new module that uses a different SQL schema to dbo

Sort:
You are not authorized to post a reply.





New Around Here





    Hi,

    I have a DNN installation that uses the default databaseowner (dbo).

    I would like to develop a module that has tables in the default database, but uses a different schema (fees) so that I can easily distinguish which tables are related to my module vs the other DNN modules.

    I don't want to use prefixes - I prefer to use a completely different schema.
    I also don't want to use a different database as I want to keep the DNN data and my module data inthe same database (for backup and admin purposes etc.)

    Previously, I used a different database for a module I developed - I simply created a new connection string for my database and passed that as a parameter when I created the DataContext.Instance - that worked great.

    How do I go about doing this using DAL+ / DAL2 and MVC?

    Thanx,

    Alon






    Veteran Member





      Well, this should be something that you could do quite easily, though I don't completely understand the benefit of what you're trying to do - unless you actually did want to use a different database.  

      All you should need to do is add a new connectionString to the connectionStrings section in your main web(dot)config.  Then, you can access it any way you wish.  That includes DAL2 (don't use the others ones at this point), raw DAL code, and any other common method (e.g., Entity Framework, Dapper, etc.).  

      Just be sure that the connectionString is using the values you configured in SQL Server to achieve your desired result. 






      New Around Here





        Posted By Will Strohl on 1/19/2024 11:58 AM

        Well, this should be something that you could do quite easily, though I don't completely understand the benefit of what you're trying to do - unless you actually did want to use a different database.  

        All you should need to do is add a new connectionString to the connectionStrings section in your main web(dot)config.  Then, you can access it any way you wish.  That includes DAL2 (don't use the others ones at this point), raw DAL code, and any other common method (e.g., Entity Framework, Dapper, etc.).  

        Just be sure that the connectionString is using the values you configured in SQL Server to achieve your desired result. 

        Hi Will,

         

        Thanx for taking the time to read my question and respond - much appreciated.

        I have added a new connectionString - but would I need to create a new SQL user that only has access to my schema in order to accomplish this?
        This might be an issue in terms of the web-hosting - I'd need to check what I can achieve in this regard.

        In the model class (Invoice.cs) - would I specify the schema as part of the TableName attribute when using DAL2: [TableName("orders.Invoice")] ?

        The purpose is simply to group the tables for my module into something that is easily identifiable and distinct from the rest of DNN:
        like: orders.Invoices and orders.InvoiceItems instead of just dbo.Invoices and dbo.InvoiceItems.
        the rest of DNN live in the 'dbo' schema and would be inter-mingled with my tables.

        Thanx,
        Alon

         

         






        New Around Here





          I played around with a test project and found that I am able to specify the schema and table in the TableName attribute like this:
          [TableName("[orders].Invoices")]

          Thanx
          Alon





          Veteran Member





            You're going to be putting this together a bit custom compared to how most folks would approach this.  I wouldn't be able to tell you exactly what to do, but the links in the resource below will give you all of the details you need to know on how to implement DAL2.  You'll need to read through some of it to find the part where you customize the query string and whatnot.  

            https://www.dnnsoftware.com/wiki/dal-2

            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