I hope this can help someone in the future. The solution that worked for me was adding IntelliJ as an 'exception' in Windows Defender. It seems that Windows Defender was blocking my connection to the database, which was causing the same error. I'm not entirely sure why, but this worked. But this link might help in some way https://intellij-support.jetbrains.com/hc/en-us/articles/360006298560-Antivirus-Impact-on-Build-Speed.