SQL Connection problem in Windows Service
-
Hello Sir/Mam I'm trying connect sql server 2000 in windows service with other system on same network. there are 4 system connected without any problem. But on other 4 system, it is giving error on connection open while starting windows service. The error is: "the service on local computer started and then stopped some services stop automatically" etc. Same Connection string working in web service without any error. But giving problem in Window Service. Is there any Configuration setting of that server or sql server 2000. Any help will be highly appreciated.........
-
Hello Sir/Mam I'm trying connect sql server 2000 in windows service with other system on same network. there are 4 system connected without any problem. But on other 4 system, it is giving error on connection open while starting windows service. The error is: "the service on local computer started and then stopped some services stop automatically" etc. Same Connection string working in web service without any error. But giving problem in Window Service. Is there any Configuration setting of that server or sql server 2000. Any help will be highly appreciated.........
Are you, by any chance, using a trusted connection? When you install a service it, by default, is installed using a specific account - and that account might not be trusted by your database.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Are you, by any chance, using a trusted connection? When you install a service it, by default, is installed using a specific account - and that account might not be trusted by your database.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
Could be that, could be a firewall, could be something else. Before trying to fix it though I'd introduce a minimum of logging in the service so in future you don't have to stare blindly at that nearly information-free message: "the service started, and then stopped unexpectedly". It's also nice to have the ability to debug service initialization. To do this, introduce a config setting and put a method like this into your service class:
static void AwaitDebugger()
{
string s = ConfigurationManager.AppSettings["debug"];
if (s == null || s.ToLower() != "true") return;DateTime until = DateTime.Now.AddSeconds(30); while (DateTime.Now < until && !Debugger.IsAttached) Thread.Sleep(50); if (Debugger.IsAttached) Debugger.Break();
}
Now in the service main thread, just insert a call to this method before doing anything else. (Not in the start method that probably simply starts the main thread; you want this method to return immediately as before. But in the thread it starts, you want to wait for a debugger to attach if so configured.) Build, deploy, and debug!
-
Could be that, could be a firewall, could be something else. Before trying to fix it though I'd introduce a minimum of logging in the service so in future you don't have to stare blindly at that nearly information-free message: "the service started, and then stopped unexpectedly". It's also nice to have the ability to debug service initialization. To do this, introduce a config setting and put a method like this into your service class:
static void AwaitDebugger()
{
string s = ConfigurationManager.AppSettings["debug"];
if (s == null || s.ToLower() != "true") return;DateTime until = DateTime.Now.AddSeconds(30); while (DateTime.Now < until && !Debugger.IsAttached) Thread.Sleep(50); if (Debugger.IsAttached) Debugger.Break();
}
Now in the service main thread, just insert a call to this method before doing anything else. (Not in the start method that probably simply starts the main thread; you want this method to return immediately as before. But in the thread it starts, you want to wait for a debugger to attach if so configured.) Build, deploy, and debug!
You might want to tell the OP this. I already know how to do this.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier