r/SQLServer • u/puffDraagon • Nov 15 '25
Question Database locked by webserver
Hi, we work with a software suite that uses an apache tomcat web server and use MSSQL as the db. Whenever the computer reboots after a windows update or power outage. The web server will not run as is says the SQL database is locked. We have another proprietary application in the suite that we use to design our systems and this can detect the lock and asks if we want to unlock the database. After which the web server will run.
Is there a way to us a command line script to unlock the sql database that we can task to run on system reboot?
13
u/edul160 Nov 15 '25
There is no „locked“ state in mssql databases.
Or is there a value „locked“ with false|true in the database? Your other propertiery application probably resets this value and the database is no longer „locked“.
If you know the table and column then it should be possible to „unlock“ with a little TSQL script from the command line.
6
u/No_Resolution_9252 Nov 15 '25
"Locked" doesn't mean anything.
There are two probably causes of this
2
u/Anlarb 1 Nov 16 '25
Is the account locked? Thats the lock that comes to mind for me.
4
u/Hairy-Ad-4018 Nov 15 '25
Op your problem Is your procedures. You shouldn’t be letting the server reboot without first shutting down the database gracefully. The db is trying to protect its self to allow self checking, transaction roll back etc to occur before it allows access.
Secondly for power outages you need an ups., and mechanism for shutting down when in the ups.
Do you perform regular db backups ? What is your disaster recovery plan ? The day is coming when you will have fatal Failure.
1
u/FreedToRoam Nov 15 '25
I would be interesting to see you use SSMS to connect and grab a screenshot when the “locked” condition occurs
You will probably find that it is not locked and it is working just fine
Or you will see a message that says “In Recovery” … in this case however there is not a magic command to instantly unlock the database
1
u/FarmboyJustice Nov 16 '25
My guess is the application could use one of several different DB back ends, and has some generic error message it returns whenever it is able to authenticate but not able to establish the required connectivity.
1
u/alinroc 4 Nov 15 '25
If it's important, put it on a UPS. Even a $150 UPS will give you the ability to gracefully shut the server down (either automatically or by someone going to the console).