PostgreSQL, Heroku, .NET Core and npgsql

I've been having fun this week building data visualisation dashboards that pull information straight out of our PostgreSQL databases and use ASP.NET Core to do some LINQ transformations and aggregation on the data. All our data is hosted on Heroku, I'm using Npgsql as an ADO.NET Data Provider, and it works beautifully - once you've worked out the exact connection string syntax needed to connect to a Heroku PostgreSQL database using ASP.NET Core.

So here it is. You'll need to get the host, port, username, password and database from your Heroku dashboard - and don't forget that if you're connecting from apps that aren't attached to Heroku directly, you'll need to manually update the configuration if you rotate your Heroku database credentials.

const string herokuConnectionString = @" Host=<host.domain.com>; Port=<port>; Username=<user>; Password=<password>; Database=<database>; Pooling=true; Use SSL Stream=True; SSL Mode=Require; TrustServerCertificate=True; ";

Happy querying!