none
Azure Portal displaying incorrect JDBC connection string

    Question

  • The Connection string page in the Azure Portals shows the wrong JDBC connection info for my PostgreSQL database.

    The connection string displayed is like:

    jdbc:postgresql://xyz.postgres.database.azure.com:5432/{your_database}?user=xyz@xuz&password={your_password}&sslmode=required

    Using this in a application using the official PostgreSQL JDBC library gives:

    2019-01-29T20:17:18.227227679Z Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.postgresql.util.PSQLException: Invalid sslmode value: required
    2019-01-29T20:17:18.227231479Z     at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81) ~[spring-jdbc-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
    2019-01-29T20:17:18.227235179Z     at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319) ~[spring-jdbc-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
    2019-01-29T20:17:18.227238779Z     ... 70 common frames omitted
    2019-01-29T20:17:18.227242180Z Caused by: org.postgresql.util.PSQLException: Invalid sslmode value: required
    2019-01-29T20:17:18.227245880Z     at org.postgresql.jdbc.SslMode.of(SslMode.java:78) ~[postgresql-42.2.5.jar!/:42.2.5]
    2019-01-29T20:17:18.227249780Z     at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:149) ~[postgresql-42.2.5.jar!/:42.2.5]
    2019-01-29T20:17:18.227253480Z     at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.5.jar!/:42.2.5]
    2019-01-29T20:17:18.227257980Z     at org.postgresql.jdbc.PgConnection.(PgConnection.java:195) ~[postgresql-42.2.5.jar!/:42.2.5]
    2019-01-29T20:17:18.227261680Z     at org.postgresql.Driver.makeConnection(Driver.java:454) ~[postgresql-42.2.5.jar!/:42.2.5]
    2019-01-29T20:17:18.227265180Z     at org.postgresql.Driver.connect(Driver.java:256) ~[postgresql-42.2.5.jar!/:42.2.5]

    The sslmode param value in the connection string page is `required` but this should be `require` (without `d`).

    When changing it to `require` it works as expected.

    Note that the PostgreSQL docs (https://t.co/bRImR1ipRW?amp=1) also mention `require` and not `required`.


    Tuesday, January 29, 2019 8:44 PM

All replies

  • Note: Connection strings that are pre-defined in the "Connection Strings" settings under your server in the Azure portal include the required parameters for common languages to connect to your database server using SSL.

    The SSL parameter varies based on the connector, for example "ssl=true" or "sslmode=require" or "sslmode=required" and other variations.

    For more details, refer “Configure SSL connectivity in Azure Database for PostgreSQL”.

    Hope this helps.

    Thursday, January 31, 2019 4:05 AM
    Moderator
  • Thx.

    I understand it's a *pre-defined* value.

    For the official PostgreSQL JDBC driver the correct value is "sslmode=require" so I wonder why the pre-defined example is "required". Doesn't make sense, or am I wrong?

    Sunday, February 3, 2019 2:23 PM
  • Yes, I understand it should be “require” for PostgreSQL JDBC.

    In general, Azure portal includes the required parameters for common languages to connect to your database server using SSL.

    Tuesday, February 5, 2019 4:47 AM
    Moderator