I have a C# console application, which interacts with a SQL Server Database, and I want to configure it to launch at system startup and before user login. My application is an infinite loop that reads/writes data from/to database (after processing), and writes log messages to the console window.
I tried windows task scheduler. The application launches, but I had two problems:
- The app can’t access the database (Error message: ” Cannot open database “MyDataBase” requested by the login. The login failed.” extracted from a log file )
- When I log in to windows, I can’t retrieve the app console, and it doesn’t figure in the task manager’s process list.
I don’t really know if this issue has a solution (or maybe a workaround) in windows, but I really need it because the server is in a distant location, and we suffer from power cut-offs in that area, so I have to check it periodically and launch my app each time the cut-off occurs.
Thanks for help.
I suspect the right thing to do here is to use two programs. First, a windows service that starts on boot and restarts whenever it fails. This service likely will need to either connect with SQL server credentials (not Windows credentials) OR run under a service ID that has access to the database. The second program would start on user login and would read/display any log messages from the windows service. Essentially it would function like “tail” on the log file written by the service, though you could come up with a more sophisticated logger registration process so that it could receive messages directly from the service if you desire.