Report this

What is the reason for this report?

Can't make api calls when using asp.net core in docker with nginx and managed postgresql database

Posted on June 13, 2020

I’m using Ubuntu 18.04 with pre-installed docker solution. My project setup is that I run my Asp.Net Core 3.1 Web Api with EntityFramework Core project in a docker container and I install Nginx on the server directly. My Web Api is connected to a Managed PostgreSQL database on DO as well using the connection string provided.

This is my Nginx configuration for the application:


server {

    server_name example.com www.example.com;

    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}

server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
   } # managed by Certbot


   if ($host = example.com) {
       return 301 https://$host$request_uri;
   } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name example.com www.example.com;
    return 404; # managed by Certbot
}

Every time I try to call the api to retrieve data from the managed database I get: ‘An exception has been raised that is likely due to a transient failure.’

Please does anyone know why this is happening?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

The error message you’re seeing “An exception has been raised that is likely due to a transient failure” is typically associated with issues in establishing a connection to a database.

Here are a few possible reasons and solutions:

  1. Incorrect Connection String: Check your connection string and make sure it’s correct and it includes the correct username, password, hostname, port, and database name.

  2. Database Is Not Accessible: Make sure your PostgreSQL database is running and accessible from your application. You can test this by trying to connect to your database using a PostgreSQL client from your application server.

  3. Firewall Rules or Trusted Sources List: Check your firewall rules to ensure that your application can connect to your PostgreSQL database. You might need to allow your Droplet’s IP address in your database trusted sources list.

To debug the issue, it would be helpful to look at the full stack trace of the exception and the inner exception if there’s any. The additional information might be helpful to pinpoint the exact cause of the issue.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.