Search code examples
grailsgrails-orm

Grails 3.2 - Disconnect from database and reconnect


I'm running some functional tests where I restore the database to a clean state in between tests. Unfortunately the restore command for SQL Server requires there be no other connections to the database. Is there a way I can call some test code to disconnect Grails/GORM and then reconnect once the database restore has completed?


Solution

  • I had the database restore code bring the database offline, do the restore, then bring the database back online.

    Adding

        properties:
            testOnBorrow: true
            testWhileIdle: true
            testOnReturn: false
            validationQuery: SELECT 1
    

    to the database setup fixed the issue by having the database reconnect automatically.