# Cannot Connect Keycloak docker to mssql database

**URL:** <https://forum.keycloak.org/t/cannot-connect-keycloak-docker-to-mssql-database/19297>\
**Category:** Miscellanaeous\
**Created:** [December 25, 2022, 2:16pm UTC](https://forum.keycloak.org/t/cannot-connect-keycloak-docker-to-mssql-database/19297 "2022-12-25T14:16:48Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![jeroni](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@jeroni](https://forum.keycloak.org/u/jeroni)\
**Post date:** [April 27, 2023, 11:57am UTC](https://forum.keycloak.org/t/cannot-connect-keycloak-docker-to-mssql-database/19297/3 "2023-04-27T11:57:53Z")

</div>

Same here. In my case I’m using a docker-compose.yml with image image: “[Quay](http://quay.io/keycloak/keycloak:latest)”  
I connect to an external mssql server where it creates a database. When the database is filled with seed data I get the same error.

Violation of UNIQUE KEY constraint “UK\_CLI\_SCOPE”. A duplicate key cannot be inserted into the dbo.CLIENT\_SCOPE object. The duplicate key value is (a8be7b83-30ee-4b12-ab6d-3bfd063ea213, role\_list).

No data or even tables are created in the database. JPA might do a full rollback because of the primary key error.  
I used an environment variable to see -verbose logs: KC\_LOG\_LEVEL=DEBUG

Questions:  
Is that just happening with sqlserver?  
How did you fix it?  
is there a problem with the creation script that JPA generates?

I fond a post about how to export the script [cloak-database-creation-keycloak.sql](http://forum.keycloak.org/t/keycloak-database-creation-keycloak-database-update-sql/5543). I couldn’t manage to configurate the export with docker-compose environment variables.

Any ideas or help will be very very welcome. 🙂

---

_[View the full topic](https://forum.keycloak.org/t/cannot-connect-keycloak-docker-to-mssql-database/19297)._
