How to fix the problem : "System.InvalidOperationException: An exception has been raised that is likely due to a transient failure." [closed]
Asked Answered
E

2

9

Let me explain : I have a .net core 3.0 API connected to a postgres database. I would like to perform basic CRUD operations with this API. I use swagger to display webrequest. Once I have created my context I migrate to the database which works very well however, as soon as I want to interact with my created table I have these errors that appears :

ExtendedSocketException : Cannot assign requested address [::1]:5433

![NpgsqlException : Exception while connecting ]2

The application is based on a docker container. (docker compose). Containers

Connection to the database :

ConnectionString

Connection

My controller :

[Route("api/[controller]")]
[ApiController]
public class CatalogueController : ControllerBase
{
    private readonly CatalogueContext _context;

    public CatalogueController(CatalogueContext context)
    {
        _context = context;
    }

    [HttpGet]
    public ActionResult<IEnumerable<Article>> GetCatalogue()
    {
        return _context.Article.ToList();
    }
}

My Context :

  public class CatalogueContext : DbContext
{
    public CatalogueContext(DbContextOptions<CatalogueContext> options) : base(options)
    {
    }
    public DbSet<Article> Article { get; set; }
}

The migration that works: migration

My Table Article on my database (I use DBeaver) :

Article

Equivoque answered 14/1, 2020 at 13:40 Comment(0)
P
2

Migrating OP's solution from a comment to an answer:

I had to change Server = localhost to Server = host.docker.internal.
– Dyn amo   Jan 14, 2020 at 14:46

Plagal answered 14/1, 2020 at 13:40 Comment(0)
D
0

This seems like a service error. i.e. you might not have added services to the program.cs file.

Daedalus answered 19/10, 2023 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.