Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Service App

Status
Not open for further replies.

ChewDoggie

Programmer
Mar 14, 2005
604
US
G'Day !

I'm having trouble connecting to a database from a Windows Service app that I'm writing. When I compile the app and then register it as a service via the 'sc' command at the command prompt and then attempt to start it, I get an error

Error 1067: The process terminated unexpectedly

When I check the event viewer, I can see the error is "Login Failed for user 'AnnAbuser'"

Can anyone give me clues as to why the database connection fails when I run this as a service, but it connects OK whilst debugging in VS ?

Thanks !

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
OK, well, I discovered by writing data to the EventLog
(Call LogNTEvent(TestData, 0, 0)) that the function that retrieved values from the registry can't do so when running as a service.

I'm almost certain there's someone in here that knows why....but it's not me. :)

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Just a wag.....

open the services panel (Start->Run, type services.msc, click ok)
Go to your service, right-click, properties
click Log On tab

By default, services start with the "Local System" account. Try changing the account to a "real" account that exists on the computer that the service is running on. If the service works as intended then you should create a new windows account specifically for this service. What I'm trying to say is... do not use an account that you use for other purposes (especially for a user). When you create this new windows account, give it a strong password, and set the password to "never expire".

I had a problem MANY years ago when I set a service to log in with my account. Several months later, I changed the password on my windows log on account. Several weeks later, I needed to re-boot the server. The service would not start because the password was wrong. It took me forever to realize it was a password issue because I had forgotten that I changed it.

I don't know if this will solve your problem, but it's easy enough to try. Good luck.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks for the WAG, George ! I can always count on you. I've added your idea to the Project Completion Checklist. Creating an account is possible, I have to speak with the sysadmin in Sept.

Just thinking out loud, though...don't Services run all of the time the computer is running, regardless of whether someone is logged on or not ?

It had occurred to me that all data that is written to the registry in VB6 is written to HK_CURRENT_USER area and if services run whether a user is logged on or not, then the services may be agnostic about the "CURRENT_USER" and thus, services may not have access to the "HK_CURRENT_USER" area, by design.

Again, just stinking out loud.

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
That makes sense. Truth is... I haven't used the registry for storing data in a very long time. In my opinion, it's a pain that isn't really necessary. I prefer flat files for storing application specific configuration information.

Of course, I don't know what you are trying to do with the registry, so it's not fair for me to suggest one thing over another.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
One of the features of the UI side of this software (RMS) is that it runs once a day and sends out all updates as one big batch job, usually in the evening but the time and interval are set by the RMS user. My task is to remove this feature from the software and install it as a service. The user of RMS sets certain parameters that must be "read" by the service and used in internal variables.

So, I was just trying to move the data OUT of the registry and move it someplace else. It'll probably end up in a database somewhere. I don't feel comfortable storing some of thsi info in an INI file.

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
I've run in to similar issues. Just remember, you'll need to store connection information somewhere so that the service knows where the database is, and is able to log in to it. I'm not comfortable leaving connection information laying around so I decided to encrypt the configuration file. Of course, once you "go down this road" you may begin to think about removing the database and just using an encrypted configuration file. Of course, this does depend on the app and the required functionality.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top