Windows Services in C#

Posted by Bhupentiwari under C# on 11/20/2015 | Points: 10 | Views : 1585 | Status : [Member] | Replies : 4
Hi
I have written Windows Service. and its start type is set to Automatic. But when in install using visual studio it does not start automatically. i have to manually start. i think it should start automatically .

Please suggest what i am missing.

When i restart my PC then too, it does not start automatically.

Thanks n Regards
Bhupendra Tiwari



Responses

Posted by: Sheonarayan on: 11/20/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Bhupen,

Please read this article http://www.dotnetfunda.com/articles/show/1095/creating-a-windows-service-using-csharp and also this thread post to get your answer http://www.dotnetfunda.com/forums/show/5256/how-to-start-windows-service-automatically.

Please ensure that while changing the setting you are logged in with Adminstrator permission.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Bhupentiwari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhupentiwari on: 11/20/2015 [Member] Starter | Points: 25

Up
0
Down
Hi Sheo Thanks for prompt reply. But now facing below issue.

Under Administrative Events i am getting below error logs. but when i start manually it run perfectly


Service cannot be started. System.Data.SqlClient.SqlException (0x80131904): Cannot open database "HWD" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\SYSTEM'.
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbCon..


Thanks n Regards
Bhupendra Tiwari

Bhupentiwari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 11/20/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
The error message clearly tells that this is the permission error to your database. Either you give permission to 'NT Authority\System' to your database or change the permission under which your service is running.

Once your user has permission to run the service as well as connect to the database, you should be fine.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Bhupentiwari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarkrishna184 on: 11/21/2015 [Member] Starter | Points: 25

Up
0
Down
Before installing the Windows Service, There is a some property need to be set, when we create a windows application after right clicking going to the property of the Windows Application,then we need to manually setting Automatic,then only first time we need to start manually its after they will ge automatically Start when you Start you System.

Thanks and Regards,
Krishna Kumar

Bhupentiwari, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response