That script does work as a good test to see if the Database is running.
I think if you’re hitting that error, you should check out the database log. Info about that is in this duplicate thread:
Since that went down a certain path, I’m not sure if it make sense to continue the conversation there, but we will want to see the Database log all the same. Can you provide the log and we’ll take a look? It may include job or machine information so feel free to provide just the errors you find there.