Search code examples
azure-web-app-servicesupabase-database

Unable to connect my azure web app to supabase database


I deployed my dotnet core 6 api app to Azure Web App (Free Tier). I would like to fetch data from a Supabase hosted database, but I get this error:

An exception has been raised that is likely due to a transient failure. Failed to connect to server:port. An attempt was made to access a socket in a way forbidden by its access permissions.

When I run the app locally everything works ok.

I'm using a direct connection with this connection string:

"User Id=postgres;Password=password;Server=server_name;Port=5432;Database=database-name"

I tried to scale up to B1 but nothing changed.


Solution

  • I encountered the same issue, which was related to the Supabase change on January 26, 2024. For more details, refer to: https://supabase.com/docs/guides/database/connecting-to-postgres

    Direct database connections will start resolving to an IPv6 address. Starting from January 26, 2024, projects will be gradually migrated to this behavior. If you connect to your database using the REST or GraphQL endpoints, this doesn't affect you. If you use the database connection string, see the GitHub discussion on how to prepare for IPv6.

    When using the connection string, you have two options:

    1. Purchase the IPv4 add-on.
    2. Utilize the connection pooler.

    I opted for the second option, which worked well for me. You can find the pooler connection string via the link provided above. At the time of writing:

    1. Visit supabase.com.
    2. Navigate to Settings -> Databases.
    3. Copy the connection string for the connection pooler.

    Supabase connection string for connection pooler