Sql-server – Unexpected Shutdown affects SQL Server DB start at OS start up

sql serversql-server-2008startup

I have an application that uses a sql server db (SQL Express 2008 R2) and starts when Windows OS starts. When the pc shutdown unexpectedly and then restart the pc the application run automatically but it' can't query the DB
I looked for the error log and it shows no record for starting the DB and I have
to open the SSMS and query the DB. Only after that the db will start (even after seconds from starting the OS)

2018-02-28 13:12:51.05 Server      Server process ID is 2420.
2018-02-28 13:12:51.50 spid7s      Starting up database 'master'.
2018-02-28 13:12:55.60 spid7s      Recovery is complete. This is an informational message only. No user action is required.
2018-02-28 13:12:58.87 spid52      Starting up database 'ReportServer$SQLEXPRESS2008R2TempDB'.
2018-02-28 13:35:27.38 spid57      Starting up database 'DBName'.

as you can see there are about 23 minutes between starting master and my db.
I also checked the service and it's running fine in the OS start.

I have 2 questions:

1- What SQL Server make to start the db and can I do that programmatically?

2- I noticed that starting 'ReportServer$SQLEXPRESS2008R2TempDB' is the beginning of the delay and it may be the cause of the delay, so can I change the order of starting the databases on the server?

Thanks in advance

Best Answer

Your DB has AUTO_CLOSE ON (which is typical of SQL Express instances, like yours). It means that the database is not opened until first accessed. This is when the first mention of it appears in the SQL ERRORLOG file.

The delay of 23 minutes is because your application is not opening the database. If you think this is a problem, it must be in your app. Are you sure your app, which must be an NT service, is configured to auto-start on OS boot?