How to configure production connection string on .NET Web API on Digital Ocean app platform.

I have recently deployed a PostgreSQL cluster on DigitalOcean. I have also uploaded a dockerized .NET Web API application on App Platform, which I now want to connect to my database cluster on DigitalOcean. Within my API I have a connection string (set up for development environment) that connects to my local PostgreSQL database. As far as my knowledge goes, once I deploy my API on App Platform the environment becomes production. I have tried using the environment variables to configure that but I did not succeed. The error that I’m getting in the Runtime Logs is :

An unhandled exception was thrown by the application. System.ArgumentNullException: Value cannot be null. (Parameter ‘connectionString’)

The error points to the place where I call my connection string in .NET - Program.cs

What I tried was adding an environment variable with the key value being the name of my connection string and the value being the connection string of my Managed PostgreSQL. I also tried using quotes for the value of the environment variable but it also did not help. Any advice on this issue will help me a lot.

Submit an answer

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!

Sign In or Sign Up to Answer

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.

I was able to solve it. For anyone that has a similar problem, I was able to solve it by using ConnectionStrings__DefaultConnection when defining the environment variable key in DigitalOcean App Platform.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel