Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. SQL Connection problem in Windows Service

SQL Connection problem in Windows Service

Scheduled Pinned Locked Moved Windows Forms
helpsysadmindatabasesql-serverworkspace
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 7992635
    wrote on last edited by
    #1

    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.........

    P 1 Reply Last reply
    0
    • M Member 7992635

      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.........

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • P Pete OHanlon

        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

        D Offline
        D Offline
        dojohansen
        wrote on last edited by
        #3

        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!

        P 1 Reply Last reply
        0
        • D dojohansen

          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!

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups