# MS SQL Server trustServerCertificate property not working

**URL:** <https://forum.keycloak.org/t/ms-sql-server-trustservercertificate-property-not-working/22599>\
**Category:** Configuring the server\
**Tags:** database\
**Created:** [June 12, 2023, 3:20am UTC](https://forum.keycloak.org/t/ms-sql-server-trustservercertificate-property-not-working/22599 "2023-06-12T03:20:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonh](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jasonh](https://forum.keycloak.org/u/jasonh)\
**Post date:** [June 12, 2023, 3:20am UTC](https://forum.keycloak.org/t/ms-sql-server-trustservercertificate-property-not-working/22599/1 "2023-06-12T03:20:13Z")

</div>

I’m trying to setup keycloak 21.1.1 with an MS SQL Server database but keep receiving this error:

```auto
2023-06-12 02:56:06,791 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to obtain JDBC connection
2023-06-12 02:56:06,791 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target". ClientConnectionId:2ba75e50-05fb-46ab-a2fa-e72cf7198e3b

```

MS SQL Server is using a self-signed certificate and so I need to either pass “trustServerCertificate=true;” or “encrypt=false;” to connection string. I’ve tried passing one or both of these parameters a variety of ways but none of them are taking effect:

- Setting additional properties: `--db-url-properties="trustServerCertificate=true;"` (I have tried it with and without quotes, with and without the semicolon at the end)
- Specifying the whole JDBC url: `--db-url jdbc:sqlserver://127.0.0.1:1433;userName=sa;password=Testing1234;trustServerCertificate=true;`
- Setting environment variable `JDBC_PARAMS="trustServerCertificate=true;"` (again, with and without quotes, and with and without the semicolon)
- All of the above using `"encrypt=false;"` instead

Any ideas why I can’t get either of these parameters to work?

---

<div class="post-metadata">

**Author:** ![AScrofani](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AScrofani](https://forum.keycloak.org/u/AScrofani)\
**Post date:** [June 13, 2023, 1:21pm UTC](https://forum.keycloak.org/t/ms-sql-server-trustservercertificate-property-not-working/22599/2 "2023-06-13T13:21:22Z")

</div>

Same issue here. I can start KC in production mode using the .conf file with the full JDBC url string but i cant make it work with “kc start” and passing the JDBC parameters in the command. Documentation seems to be a bit short about this and already tried all of those combinations you mention.

---

<div class="post-metadata">

**Author:** ![matheusAMDS](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/matheusamds/32/9247_2.png) [@matheusAMDS](https://forum.keycloak.org/u/matheusAMDS)\
**Post date:** [November 13, 2023, 11:37am UTC](https://forum.keycloak.org/t/ms-sql-server-trustservercertificate-property-not-working/22599/3 "2023-11-13T11:37:37Z")

</div>

Did any of you solve this problem? I’m having the same problem here as well

---

<div class="post-metadata">

**Author:** ![i\_sophist](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@i\_sophist](https://forum.keycloak.org/u/i_sophist)\
**Post date:** [February 1, 2024, 7:53pm UTC](https://forum.keycloak.org/t/ms-sql-server-trustservercertificate-property-not-working/22599/4 "2024-02-01T19:53:33Z")

</div>

I’ve been having the issue on Windows Server 2016. I found this previous fix from [version 20](https://github.com/keycloak/keycloak/issues/15994). I added this is to my keycloak.conf file:

```config
db-url-database=keycloak23
db-url-host=server.domain.org
db-url-port=1433
db-url-properties=";trustServerCertificate=true;encrypted=false"

```

After some trial and error, I’ve at least stopped receiving PKIX errors, but now I’m getting

```plaintext
2024-02-01 11:43:17,020 WARN [org.infinispan.CONFIG] (keycloak-cache-init) ISPN000569: Unable to persist Infinispan internal caches as no global state enabled
2024-02-01 11:43:18,829 WARN [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread) HHH000342: Could not obtain connection to query metadata: java.lang.NullPointerException: Cannot invoke "org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(java.sql.SQLException, String)" because the return value of "org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.sqlExceptionHelper()" is null
2024-02-01 11:43:24,611 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to obtain JDBC connection
2024-02-01 11:43:24,611 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Acquisition timeout while waiting for new connection

```

So that’s…progress…?
