trying to get the self hosted service to auto start can sometimes not work, even if you set it to delayed.
The error more than likely will be shown by something like this in the event log.
Service cannot be started. System.Data.SqlClient.SqlException (0x80131904): Cannot open database "JiwaDemo7181" requested by the login. The login failed.
Login failed for user 'JiwaLogin'.
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectio...
and is because SQL Server has not finished starting up before the API does.
The following command will fix the problem by creating a dependency on SQL Server for the API service.
- Code: Select all
sc config JiwaAPISelfHostedService.exe depend= MSSQLSERVER