how connect both PostgreSQL and timescale databases into ASP.NET MVC web.config file
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
Possible duplicate of The entry '' has already been added error
– Shahar Shukrani
Nov 22 at 16:26
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
asp.net asp.net-mvc postgresql
asked Nov 22 at 16:16
munchi
11
11
Possible duplicate of The entry '' has already been added error
– Shahar Shukrani
Nov 22 at 16:26
add a comment |
Possible duplicate of The entry '' has already been added error
– Shahar Shukrani
Nov 22 at 16:26
Possible duplicate of The entry '' has already been added error
– Shahar Shukrani
Nov 22 at 16:26
Possible duplicate of The entry '' has already been added error
– Shahar Shukrani
Nov 22 at 16:26
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
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.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
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.
add a comment |
up vote
0
down vote
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.
add a comment |
up vote
0
down vote
up vote
0
down vote
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.
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.
answered Nov 24 at 3:30
munchi
11
11
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Possible duplicate of The entry '' has already been added error
– Shahar Shukrani
Nov 22 at 16:26