how connect both PostgreSQL and timescale databases into ASP.NET MVC web.config file












0















I created a project "SmartHome" using the ASP.NET MVC. I used two types of databases;




  • PostgreSQL

  • TIMESCALE


Here, I integrate the TIMESCALE with the PostgreSQL.



I connected the PostgreSQL with ASP.NET MVC and it is working fine. the connection string as below.



<add name="SmartHomeContext" 
connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;
User Id=postgres;Password=postdata;" providerName="Npgsql" />


here database names of;




  • PostgreSQL = smarthome

  • TIMESCALE = smarthomeData


My problem is " How TIMESCALE database connect to work with same "SmartHome" database in the ASP.NET MVC ? "



I tried the connection string for TIMESCALE as below.



<add name="SmartHomeContext" 
connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;
User Id=postgres;Password=postdata;" providerName="Npgsql" />


but it shows the below error:
"The entry 'SmartHomeContext' has already been added."



Please help me or guide me, I am very new to do this.










share|improve this question























  • Possible duplicate of The entry '' has already been added error

    – Shahar Shokrani
    Nov 22 '18 at 16:26
















0















I created a project "SmartHome" using the ASP.NET MVC. I used two types of databases;




  • PostgreSQL

  • TIMESCALE


Here, I integrate the TIMESCALE with the PostgreSQL.



I connected the PostgreSQL with ASP.NET MVC and it is working fine. the connection string as below.



<add name="SmartHomeContext" 
connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;
User Id=postgres;Password=postdata;" providerName="Npgsql" />


here database names of;




  • PostgreSQL = smarthome

  • TIMESCALE = smarthomeData


My problem is " How TIMESCALE database connect to work with same "SmartHome" database in the ASP.NET MVC ? "



I tried the connection string for TIMESCALE as below.



<add name="SmartHomeContext" 
connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;
User Id=postgres;Password=postdata;" providerName="Npgsql" />


but it shows the below error:
"The entry 'SmartHomeContext' has already been added."



Please help me or guide me, I am very new to do this.










share|improve this question























  • Possible duplicate of The entry '' has already been added error

    – Shahar Shokrani
    Nov 22 '18 at 16:26














0












0








0








I created a project "SmartHome" using the ASP.NET MVC. I used two types of databases;




  • PostgreSQL

  • TIMESCALE


Here, I integrate the TIMESCALE with the PostgreSQL.



I connected the PostgreSQL with ASP.NET MVC and it is working fine. the connection string as below.



<add name="SmartHomeContext" 
connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;
User Id=postgres;Password=postdata;" providerName="Npgsql" />


here database names of;




  • PostgreSQL = smarthome

  • TIMESCALE = smarthomeData


My problem is " How TIMESCALE database connect to work with same "SmartHome" database in the ASP.NET MVC ? "



I tried the connection string for TIMESCALE as below.



<add name="SmartHomeContext" 
connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;
User Id=postgres;Password=postdata;" providerName="Npgsql" />


but it shows the below error:
"The entry 'SmartHomeContext' has already been added."



Please help me or guide me, I am very new to do this.










share|improve this question














I created a project "SmartHome" using the ASP.NET MVC. I used two types of databases;




  • PostgreSQL

  • TIMESCALE


Here, I integrate the TIMESCALE with the PostgreSQL.



I connected the PostgreSQL with ASP.NET MVC and it is working fine. the connection string as below.



<add name="SmartHomeContext" 
connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;
User Id=postgres;Password=postdata;" providerName="Npgsql" />


here database names of;




  • PostgreSQL = smarthome

  • TIMESCALE = smarthomeData


My problem is " How TIMESCALE database connect to work with same "SmartHome" database in the ASP.NET MVC ? "



I tried the connection string for TIMESCALE as below.



<add name="SmartHomeContext" 
connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;
User Id=postgres;Password=postdata;" providerName="Npgsql" />


but it shows the below error:
"The entry 'SmartHomeContext' has already been added."



Please help me or guide me, I am very new to do this.







asp.net asp.net-mvc postgresql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 16:16









munchimunchi

11




11













  • Possible duplicate of The entry '' has already been added error

    – Shahar Shokrani
    Nov 22 '18 at 16:26



















  • Possible duplicate of The entry '' has already been added error

    – Shahar Shokrani
    Nov 22 '18 at 16:26

















Possible duplicate of The entry '' has already been added error

– Shahar Shokrani
Nov 22 '18 at 16:26





Possible duplicate of The entry '' has already been added error

– Shahar Shokrani
Nov 22 '18 at 16:26












1 Answer
1






active

oldest

votes


















0














Above error ("The entry 'SmartHomeContext' has already been added.") was solved and the connection also done. the steps are followed as below;





  • Web.config file : add a another connection string for TIMESCALE database as "SmartHomeContext1". In the below code snippet, third connection string.



    <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=
    (LocalDb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|aspnet-SmartHome-
    20181019034449.mdf;Initial Catalog=aspnet-SmartHome-20181019034449;Integrated
    Security=True" providerName="System.Data.SqlClient" />

    <add name="SmartHomeContext"
    connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;User
    Id=postgres;Password=postdata;" providerName="Npgsql" />

    <add name="SmartHomeContext1"
    connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;User
    Id=postgres;Password=postdata;" providerName="Npgsql" />
    </connectionStrings>


  • create "timescalecontext.cs" file in the Model as attached image.
    timescalecontext.cs in the Models folder in visual studio


  • already I created a table in the database "smarthomeData" as attached image.
    timescale database


  • then, code the "timescalecontext.cs" file as below.



    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Web;

    namespace SmartHome.Models
    {
    public class timescalecontext : DbContext
    {

    public timescalecontext() : base("name=SmartHomeContext1")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
    modelBuilder.HasDefaultSchema("public");
    base.OnModelCreating(modelBuilder);
    }

    public System.Data.Entity.DbSet<SmartHome.Models.DeviceReading> DeviceReadings { get; set; }
    public System.Data.Entity.DbSet<SmartHome.Models.Event> Events { get; set; }
    }

    }



  • since the controller file already created before make the above connection, change the code matched with the Dbcontext as below:



    namespace SmartHome.Controllers
    {
    public class DeviceReadingsController : Controller
    {
    private timescalecontext db = new timescalecontext();



after all that, It worked. Hope, this will be helpful.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434875%2fhow-connect-both-postgresql-and-timescale-databases-into-asp-net-mvc-web-config%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Above error ("The entry 'SmartHomeContext' has already been added.") was solved and the connection also done. the steps are followed as below;





    • Web.config file : add a another connection string for TIMESCALE database as "SmartHomeContext1". In the below code snippet, third connection string.



      <connectionStrings>
      <add name="DefaultConnection" connectionString="Data Source=
      (LocalDb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|aspnet-SmartHome-
      20181019034449.mdf;Initial Catalog=aspnet-SmartHome-20181019034449;Integrated
      Security=True" providerName="System.Data.SqlClient" />

      <add name="SmartHomeContext"
      connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;User
      Id=postgres;Password=postdata;" providerName="Npgsql" />

      <add name="SmartHomeContext1"
      connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;User
      Id=postgres;Password=postdata;" providerName="Npgsql" />
      </connectionStrings>


    • create "timescalecontext.cs" file in the Model as attached image.
      timescalecontext.cs in the Models folder in visual studio


    • already I created a table in the database "smarthomeData" as attached image.
      timescale database


    • then, code the "timescalecontext.cs" file as below.



      using System;
      using System.Collections.Generic;
      using System.Data.Entity;
      using System.Linq;
      using System.Web;

      namespace SmartHome.Models
      {
      public class timescalecontext : DbContext
      {

      public timescalecontext() : base("name=SmartHomeContext1")
      {
      }

      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
      modelBuilder.HasDefaultSchema("public");
      base.OnModelCreating(modelBuilder);
      }

      public System.Data.Entity.DbSet<SmartHome.Models.DeviceReading> DeviceReadings { get; set; }
      public System.Data.Entity.DbSet<SmartHome.Models.Event> Events { get; set; }
      }

      }



    • since the controller file already created before make the above connection, change the code matched with the Dbcontext as below:



      namespace SmartHome.Controllers
      {
      public class DeviceReadingsController : Controller
      {
      private timescalecontext db = new timescalecontext();



    after all that, It worked. Hope, this will be helpful.






    share|improve this answer




























      0














      Above error ("The entry 'SmartHomeContext' has already been added.") was solved and the connection also done. the steps are followed as below;





      • Web.config file : add a another connection string for TIMESCALE database as "SmartHomeContext1". In the below code snippet, third connection string.



        <connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=
        (LocalDb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|aspnet-SmartHome-
        20181019034449.mdf;Initial Catalog=aspnet-SmartHome-20181019034449;Integrated
        Security=True" providerName="System.Data.SqlClient" />

        <add name="SmartHomeContext"
        connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;User
        Id=postgres;Password=postdata;" providerName="Npgsql" />

        <add name="SmartHomeContext1"
        connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;User
        Id=postgres;Password=postdata;" providerName="Npgsql" />
        </connectionStrings>


      • create "timescalecontext.cs" file in the Model as attached image.
        timescalecontext.cs in the Models folder in visual studio


      • already I created a table in the database "smarthomeData" as attached image.
        timescale database


      • then, code the "timescalecontext.cs" file as below.



        using System;
        using System.Collections.Generic;
        using System.Data.Entity;
        using System.Linq;
        using System.Web;

        namespace SmartHome.Models
        {
        public class timescalecontext : DbContext
        {

        public timescalecontext() : base("name=SmartHomeContext1")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
        modelBuilder.HasDefaultSchema("public");
        base.OnModelCreating(modelBuilder);
        }

        public System.Data.Entity.DbSet<SmartHome.Models.DeviceReading> DeviceReadings { get; set; }
        public System.Data.Entity.DbSet<SmartHome.Models.Event> Events { get; set; }
        }

        }



      • since the controller file already created before make the above connection, change the code matched with the Dbcontext as below:



        namespace SmartHome.Controllers
        {
        public class DeviceReadingsController : Controller
        {
        private timescalecontext db = new timescalecontext();



      after all that, It worked. Hope, this will be helpful.






      share|improve this answer


























        0












        0








        0







        Above error ("The entry 'SmartHomeContext' has already been added.") was solved and the connection also done. the steps are followed as below;





        • Web.config file : add a another connection string for TIMESCALE database as "SmartHomeContext1". In the below code snippet, third connection string.



          <connectionStrings>
          <add name="DefaultConnection" connectionString="Data Source=
          (LocalDb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|aspnet-SmartHome-
          20181019034449.mdf;Initial Catalog=aspnet-SmartHome-20181019034449;Integrated
          Security=True" providerName="System.Data.SqlClient" />

          <add name="SmartHomeContext"
          connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;User
          Id=postgres;Password=postdata;" providerName="Npgsql" />

          <add name="SmartHomeContext1"
          connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;User
          Id=postgres;Password=postdata;" providerName="Npgsql" />
          </connectionStrings>


        • create "timescalecontext.cs" file in the Model as attached image.
          timescalecontext.cs in the Models folder in visual studio


        • already I created a table in the database "smarthomeData" as attached image.
          timescale database


        • then, code the "timescalecontext.cs" file as below.



          using System;
          using System.Collections.Generic;
          using System.Data.Entity;
          using System.Linq;
          using System.Web;

          namespace SmartHome.Models
          {
          public class timescalecontext : DbContext
          {

          public timescalecontext() : base("name=SmartHomeContext1")
          {
          }

          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
          modelBuilder.HasDefaultSchema("public");
          base.OnModelCreating(modelBuilder);
          }

          public System.Data.Entity.DbSet<SmartHome.Models.DeviceReading> DeviceReadings { get; set; }
          public System.Data.Entity.DbSet<SmartHome.Models.Event> Events { get; set; }
          }

          }



        • since the controller file already created before make the above connection, change the code matched with the Dbcontext as below:



          namespace SmartHome.Controllers
          {
          public class DeviceReadingsController : Controller
          {
          private timescalecontext db = new timescalecontext();



        after all that, It worked. Hope, this will be helpful.






        share|improve this answer













        Above error ("The entry 'SmartHomeContext' has already been added.") was solved and the connection also done. the steps are followed as below;





        • Web.config file : add a another connection string for TIMESCALE database as "SmartHomeContext1". In the below code snippet, third connection string.



          <connectionStrings>
          <add name="DefaultConnection" connectionString="Data Source=
          (LocalDb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|aspnet-SmartHome-
          20181019034449.mdf;Initial Catalog=aspnet-SmartHome-20181019034449;Integrated
          Security=True" providerName="System.Data.SqlClient" />

          <add name="SmartHomeContext"
          connectionString="Server=127.0.0.1;Port=5432;Database=smarthome;User
          Id=postgres;Password=postdata;" providerName="Npgsql" />

          <add name="SmartHomeContext1"
          connectionString="Server=127.0.0.1;Port=5432;Database=smarthomeData;User
          Id=postgres;Password=postdata;" providerName="Npgsql" />
          </connectionStrings>


        • create "timescalecontext.cs" file in the Model as attached image.
          timescalecontext.cs in the Models folder in visual studio


        • already I created a table in the database "smarthomeData" as attached image.
          timescale database


        • then, code the "timescalecontext.cs" file as below.



          using System;
          using System.Collections.Generic;
          using System.Data.Entity;
          using System.Linq;
          using System.Web;

          namespace SmartHome.Models
          {
          public class timescalecontext : DbContext
          {

          public timescalecontext() : base("name=SmartHomeContext1")
          {
          }

          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
          modelBuilder.HasDefaultSchema("public");
          base.OnModelCreating(modelBuilder);
          }

          public System.Data.Entity.DbSet<SmartHome.Models.DeviceReading> DeviceReadings { get; set; }
          public System.Data.Entity.DbSet<SmartHome.Models.Event> Events { get; set; }
          }

          }



        • since the controller file already created before make the above connection, change the code matched with the Dbcontext as below:



          namespace SmartHome.Controllers
          {
          public class DeviceReadingsController : Controller
          {
          private timescalecontext db = new timescalecontext();



        after all that, It worked. Hope, this will be helpful.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 3:30









        munchimunchi

        11




        11
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434875%2fhow-connect-both-postgresql-and-timescale-databases-into-asp-net-mvc-web-config%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy