|
| 1 | +--- |
| 2 | +title: Integrate Neon Serverless Postgres with Service Connector |
| 3 | +description: Integrate Neon Serverless Postgres into your application with Service Connector. |
| 4 | +author: maud-lv |
| 5 | +ms.author: malev |
| 6 | +ms.service: service-connector |
| 7 | +ms.topic: how-to |
| 8 | +ms.custom: engagement-fy23 |
| 9 | +ms.date: 02/21/2025 |
| 10 | +--- |
| 11 | + |
| 12 | +# Integrate Neon Serverless Postgres with Service Connector |
| 13 | + |
| 14 | +This page shows supported authentication methods and clients, and shows sample code you can use to connect Neon Serverless Postgres from Azure compute services using Service Connector. You might still be able to connect to Neon Serverless Postgres in other programming languages without using Service Connector. This page also shows default environment variable names and values (or Spring Boot configuration) you get when you create the service connection. |
| 15 | + |
| 16 | +## Supported compute services |
| 17 | + |
| 18 | +Service Connector can be used to connect the following compute services to Neon Serverless Postgres: |
| 19 | + |
| 20 | +- Azure App Service |
| 21 | +- Azure Container Apps |
| 22 | +- Azure Functions |
| 23 | +- Azure Kubernetes Service (AKS) |
| 24 | +- Azure Spring Apps |
| 25 | + |
| 26 | +## Supported authentication types and client types |
| 27 | + |
| 28 | +The table below shows which combinations of authentication methods and clients are supported for connecting your compute service to Neon Serverless Postgres using Service Connector. A “Yes” indicates that the combination is supported, while a “No” indicates that it is not supported. |
| 29 | + |
| 30 | +| Client type | System-assigned managed identity | User-assigned managed identity | Secret/connection string | Service principal | |
| 31 | +|---------------------------|:--------------------------------:|:------------------------------:|:------------------------:|:-----------------:| |
| 32 | +| .NET | No | No | Yes | No | |
| 33 | +| Go (pg) | No | No | Yes | No | |
| 34 | +| Java (JDBC) | No | No | Yes | No | |
| 35 | +| Java - Spring Boot (JDBC) | No | No | Yes | No | |
| 36 | +| Node.js (pg) | No | No | Yes | No | |
| 37 | +| PHP (native) | No | No | Yes | No | |
| 38 | +| Python (psycopg2) | No | No | Yes | No | |
| 39 | +| Python-Django | No | No | Yes | No | |
| 40 | +| Ruby (ruby-pg) | No | No | Yes | No | |
| 41 | +| None | No | No | Yes | No | |
| 42 | + |
| 43 | +This table indicates that all combinations of client types and authentication methods in the table are supported. All client types can use any of the authentication methods to connect to Neon Serverless Postgres using Service Connector. |
| 44 | + |
| 45 | +## Default environment variable names or application properties and sample code |
| 46 | + |
| 47 | +Reference the connection details and sample code in the following tables, according to your connection's authentication type and client type, to connect compute services to Neon Serverless Postgres. For more information about naming conventions, check the [Service Connector internals](concept-service-connector-internals.md#configuration-naming-convention) article. |
| 48 | + |
| 49 | +### Connection String |
| 50 | + |
| 51 | +> [!WARNING] |
| 52 | +> Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a very high degree of trust in the application, and carries risks that are not present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable. |
| 53 | +
|
| 54 | +#### [.NET](#tab/dotnet) |
| 55 | + |
| 56 | +| Default environment variable name | Description | Example value | |
| 57 | +| ------------------------------------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | |
| 58 | +| `NEON_POSTGRESQL_CONNECTIONSTRING` | .NET PostgreSQL connection string | `Server=ep-still-mud-a12aa123.eastus2.azure.neon.tech;Database=<database-name>;Port=5432;Ssl Mode=Require;User Id=<username>;` | |
| 59 | + |
| 60 | +#### [Java](#tab/java) |
| 61 | + |
| 62 | +| Default environment variable name | Description | Example value | |
| 63 | +| ------------------------------------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 64 | +| `NEON_POSTGRESQL_CONNECTIONSTRING` | JDBC PostgreSQL connection string | `jdbc:postgresql://ep-still-mud-a12aa123.eastus2.azure.neon.tech:5432/<database-name>?sslmode=require&user=<username>&password=<password>` | |
| 65 | + |
| 66 | +#### [SpringBoot](#tab/springBoot) |
| 67 | + |
| 68 | +| Application properties | Description | Example value | |
| 69 | +| ------------------------------ | ----------------- | --------------------------------------------------------------------------------------------------------------- | |
| 70 | +| `spring.datasource.url` | Database URL | `jdbc:postgresql://ep-still-mud-a12aa123.eastus2.azure.neon.tech:5432/<database-name>?sslmode=require` | |
| 71 | +| `spring.datasource.username` | Database username | `<username>` | |
| 72 | +| `spring.datasource.password` | Database password | `<password>` | |
| 73 | + |
| 74 | +#### [Python](#tab/python) |
| 75 | + |
| 76 | +| Default environment variable name | Description | Example value | |
| 77 | +| ------------------------------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 78 | +| `NEON_POSTGRESQL_CONNECTIONSTRING` | psycopg2 connection string | `dbname=<database-name> host=ep-still-mud-a12aa123.eastus2.azure.neon.tech port=5432 sslmode=require user=<username> password=<password>` | |
| 79 | + |
| 80 | +#### [Django](#tab/django) |
| 81 | + |
| 82 | +| Default environment variable name | Description | Example value | |
| 83 | +| --------------------------------- | ----------------- | -------------------------------------------------------- | |
| 84 | +| `NEON_POSTGRESQL_NAME` | Database name | `<database-name>` | |
| 85 | +| `NEON_POSTGRESQL_HOST` | Database host URL | `ep-still-mud-a12aa123.eastus2.azure.neon.tech` | |
| 86 | +| `NEON_POSTGRESQL_USER` | Database username | `<username>` | |
| 87 | +| `NEON_POSTGRESQL_PASSWORD` | Database password | `<database-password>` | |
| 88 | + |
| 89 | +#### [Go](#tab/go) |
| 90 | + |
| 91 | +| Default environment variable name | Description | Example value | |
| 92 | +|-------------------------------------|---------------------------------|---------------------------------------------------------------------------------------------------------------------------------| |
| 93 | +| `NEON_POSTGRESQL_CONNECTIONSTRING` | Go PostgreSQL connection string | `host=ep-still-mud-a12aa123.eastus2.azure.neon.tech dbname=<database-name> sslmode=require user=<username> password=<password>` | |
| 94 | + |
| 95 | +#### [NodeJS](#tab/nodejs) |
| 96 | + |
| 97 | +| Default environment variable name | Description | Example value | |
| 98 | +| --------------------------------- | ----------------- | -------------------------------------------------------- | |
| 99 | +| `NEON_POSTGRESQL_HOST` | Database host URL | `ep-still-mud-a12aa123.eastus2.azure.neon.tech` | |
| 100 | +| `NEON_POSTGRESQL_USER` | Database username | `<username>` | |
| 101 | +| `NEON_POSTGRESQL_PASSWORD` | Database password | `<password>` | |
| 102 | +| `NEON_POSTGRESQL_DATABASE` | Database name | `<database-name>` | |
| 103 | +| `NEON_POSTGRESQL_PORT` | Port number | `5432` | |
| 104 | +| `NEON_POSTGRESQL_SSL` | SSL option | `true` | |
| 105 | + |
| 106 | +#### [PHP](#tab/php) |
| 107 | + |
| 108 | +| Default environment variable name | Description | Example value | |
| 109 | +|-----------------------------------|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------| |
| 110 | +| `NEON_POSTGRESQL_CONNECTIONSTRING` | PHP native PostgreSQL connection string | `host=ep-still-mud-a12aa123.eastus2.azure.neon.tech port=5432 dbname=<database-name> sslmode=require user=<username> password=<password>` | |
| 111 | + |
| 112 | +#### [Ruby](#tab/ruby) |
| 113 | + |
| 114 | +| Default environment variable name | Description | Example value | |
| 115 | +|-----------------------------------|---------------------------------|----------------------------------------------------------------------------------| |
| 116 | +| `NEON_POSTGRESQL_CONNECTIONSTRING` | Ruby PostgreSQL connection string | `host=<your-postgres-server-name>.postgres.database.azure.com port=5432 dbname=<database-name> sslmode=require user=<username> password=<password>` | |
| 117 | + |
| 118 | +#### [Other](#tab/none) |
| 119 | + |
| 120 | +| Default environment variable name | Description | Example value | |
| 121 | +| --------------------------------- | ----------------- | -------------------------------------------------------- | |
| 122 | +| `NEON_POSTGRESQL_HOST` | Database host URL | `ep-still-mud-a12aa123.eastus2.azure.neon.tech` | |
| 123 | +| `NEON_POSTGRESQL_USERNAME` | Database username | `<username>` | |
| 124 | +| `NEON_POSTGRESQL_DATABASE` | Database name | `<database-name>` | |
| 125 | +| `NEON_POSTGRESQL_PORT` | Port number | `5432` | |
| 126 | +| `NEON_POSTGRESQL_SSL` | SSL option | `true` | |
| 127 | +| `NEON_POSTGRESQL_PASSWORD` | Database password | `<password>`| |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +#### Sample code |
| 132 | + |
| 133 | +Refer to the steps and code below to connect to Neon Serverless Postgres using a connection string. |
| 134 | +[!INCLUDE [code sample for postgresql secrets](./includes/code-neon-postgres-secret.md)] |
| 135 | + |
| 136 | + |
| 137 | +## Next steps |
| 138 | + |
| 139 | +Follow the tutorials listed below to learn more about Service Connector. |
| 140 | + |
| 141 | +> [!div class="nextstepaction"] |
| 142 | +> [Learn about Service Connector concepts](./concept-service-connector-internals.md) |
0 commit comments