Connections not closing with OrmLite PostgreSQL

In my API I only use the Db object on the Service base class. I am using Azure basic PostgreSQL package which only allows 50 connections and I frequently hit errors of no connection slots available.

Looking in pg_activity I can see the connections fill up as I use the API, especially when I use some import features that make a lot of queries. They seem to be status “idle” and eventually timeout. This isn’t a production app, just something in development with just me using it.

Do you have any idea why the connections are not being disposed of and remaining open?

Most RDBMS ADO.NET providers (OrmLite uses Npgsql for PostgreSQL) uses connection pooling by default, here’s the params you can use to configure it in the connection string:

It sounds like you want a max of 50 connections.