SQL Server database reconnection issues in Grails application

I have a Grails 4.0.3 app that loses connection to SQL Server when the database server restarts. The app doesn’t reconnect automatically when the server comes back online.

I tried adding autoReconnect=true to my connection string in application.yml but it doesn’t work:

url: jdbc:sqlserver://${DB_SERVER};databaseName=${MY_DB};domain=${DOMAIN_NAME};autoReconnect=true

I also found this config online but it seems to be MySQL specific:

environments:
    development:
        dataSource:
            properties:
                dbProperties:
                    autoReconnect: true

What’s the correct way to configure automatic database reconnection for SQL Server in Grails?

Yeah, this is a common issue with SQL Server and Grails. That autoReconnect parameter only works for MySQL - SQL Server’s JDBC driver ignores it completely. You need to handle reconnection through your connection pool instead. In your application.yml, add these under dataSource: testOnBorrow: true, testWhileIdle: true, validationQuery: "SELECT 1", and timeBetweenEvictionRunsMillis: 30000. I’ve used this setup in production and it handles database restarts perfectly.

same headaches here. check ur connection pool settings - it might be holding dead connections. try maxActive: 10 and minIdle: 2 to force rotation. also set removeAbandoned: true for stuck connections.

interesting problem! I’ve seen this before. Are you getting specific error msgs when reconnection fails? What connection pool does Grails 4 use by defualt? The validation query approach looks good, but have you tried tweaking the pool timeout settings?