windows service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J

    windows service

    I create a windows application to delete old data in sql server without any
    problem. Then I create a windows service to handle this task due to this task is
    a daily basis job. I also have let this service write to log file before and
    after service to start and finisheddelete job. When I opened log file,
    everything is fine, no error message, but data is SQL server did not deleted.

    So, does windows service acts different than normal windows application?
    Thanks.
  • Salvador

    #2
    RE: windows service

    Hi,

    The first thing that you should notice is that the service uses another
    account to run, maybe you have a permissions issue. Try to load your server
    with your user and check again.

    hope this helps
    Salva


    "J" wrote:
    [color=blue]
    > I create a windows application to delete old data in sql server without any
    > problem. Then I create a windows service to handle this task due to this task is
    > a daily basis job. I also have let this service write to log file before and
    > after service to start and finisheddelete job. When I opened log file,
    > everything is fine, no error message, but data is SQL server did not deleted.
    >
    > So, does windows service acts different than normal windows application?
    > Thanks.
    >[/color]

    Comment

    • J

      #3
      Re: windows service

      Well, the account for the windows service is set to "LocalSyste m", and I have
      assigned user id and password for the SQL server connection string.

      Any idea?
      Thanks.


      On Tue, 12 Apr 2005 09:36:03 -0700, "Salvador"
      <Salvador@discu ssions.microsof t.com> wrote:
      [color=blue]
      >Hi,
      >
      >The first thing that you should notice is that the service uses another
      >account to run, maybe you have a permissions issue. Try to load your server
      >with your user and check again.
      >
      >hope this helps
      >Salva[/color]

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: windows service

        J,

        The LocalSystem account does not have permissions to access the network
        either. You need to use the NetworkService account in order to access the
        network (assuming the SQL server is on another machine or you are accessing
        it through TCP/IP on the same machine).

        Hope this helps.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "J" <j@NoSpam.org > wrote in message
        news:rdun5199k0 i3jhcg98q1e7g6n rq2f6e8g5@4ax.c om...[color=blue]
        > Well, the account for the windows service is set to "LocalSyste m", and I
        > have
        > assigned user id and password for the SQL server connection string.
        >
        > Any idea?
        > Thanks.
        >
        >
        > On Tue, 12 Apr 2005 09:36:03 -0700, "Salvador"
        > <Salvador@discu ssions.microsof t.com> wrote:
        >[color=green]
        >>Hi,
        >>
        >>The first thing that you should notice is that the service uses another
        >>account to run, maybe you have a permissions issue. Try to load your
        >>server
        >>with your user and check again.
        >>
        >>hope this helps
        >>Salva[/color]
        >[/color]


        Comment

        • Salvador

          #5
          Re: windows service

          Hi,

          Ok, You can run the Profiler to check if the service is executing any SQL
          statement, otherwise I recommend you to debug the service, move the OnStart
          content to OnContinue, so you can start the service without executing
          anything, than attach the debugger and finally pause and resume the service.
          If you have set the breakpoint on OnContinue it will stop on the debugger.

          hope this helps,
          Salva


          "J" wrote:
          [color=blue]
          > Well, the account for the windows service is set to "LocalSyste m", and I have
          > assigned user id and password for the SQL server connection string.
          >
          > Any idea?
          > Thanks.
          >
          >
          > On Tue, 12 Apr 2005 09:36:03 -0700, "Salvador"
          > <Salvador@discu ssions.microsof t.com> wrote:
          >[color=green]
          > >Hi,
          > >
          > >The first thing that you should notice is that the service uses another
          > >account to run, maybe you have a permissions issue. Try to load your server
          > >with your user and check again.
          > >
          > >hope this helps
          > >Salva[/color]
          >
          >[/color]

          Comment

          • Willy Denoyette [MVP]

            #6
            Re: windows service


            "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
            message news:uoGeM$3PFH A.2520@tk2msftn gp13.phx.gbl...[color=blue]
            > J,
            >
            > The LocalSystem account does not have permissions to access the network
            > either. You need to use the NetworkService account in order to access the
            > network (assuming the SQL server is on another machine or you are
            > accessing it through TCP/IP on the same machine).
            >
            > Hope this helps.[/color]

            OP said he was using a SQL server connection string specifying explicit
            credentials, so the service account is not an issue here.

            Willy.


            Comment

            • Willy Denoyette [MVP]

              #7
              Re: windows service


              "J" <j@NoSpam.org > wrote in message
              news:rdun5199k0 i3jhcg98q1e7g6n rq2f6e8g5@4ax.c om...[color=blue]
              > Well, the account for the windows service is set to "LocalSyste m", and I
              > have
              > assigned user id and password for the SQL server connection string.
              >
              > Any idea?
              > Thanks.
              >
              >[/color]

              Please post you connection string, and some code would help also.

              Willy.


              Comment

              • Nicholas Paldino [.NET/C# MVP]

                #8
                Re: windows service

                Willy,

                If the SQL server is on another machine, and the service is running
                under the Local System account (which doesn't have network access), then
                yes, it will be an issue.

                --
                - Nicholas Paldino [.NET/C# MVP]
                - mvp@spam.guard. caspershouse.co m

                "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                news:euDGRD4PFH A.604@TK2MSFTNG P10.phx.gbl...[color=blue]
                >
                > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
                > in message news:uoGeM$3PFH A.2520@tk2msftn gp13.phx.gbl...[color=green]
                >> J,
                >>
                >> The LocalSystem account does not have permissions to access the
                >> network either. You need to use the NetworkService account in order to
                >> access the network (assuming the SQL server is on another machine or you
                >> are accessing it through TCP/IP on the same machine).
                >>
                >> Hope this helps.[/color]
                >
                > OP said he was using a SQL server connection string specifying explicit
                > credentials, so the service account is not an issue here.
                >
                > Willy.
                >
                >[/color]


                Comment

                • Ignacio Machin \( .NET/ C# MVP \)

                  #9
                  Re: windows service

                  Hi,

                  I think that the LocalSystem does has permission to access the network, I
                  have a couple of processes running as LocalSystem and they listen to and
                  send/receive data over the network.

                  Maybe the OP is running the SQL server with win. auth.

                  Why don't you put a try/catch when you open the connection and perform the
                  DB operations?

                  cheers,

                  --
                  Ignacio Machin,
                  ignacio.machin AT dot.state.fl.us
                  Florida Department Of Transportation


                  "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
                  message news:uoGeM$3PFH A.2520@tk2msftn gp13.phx.gbl...[color=blue]
                  > J,
                  >
                  > The LocalSystem account does not have permissions to access the network
                  > either. You need to use the NetworkService account in order to access the
                  > network (assuming the SQL server is on another machine or you are
                  > accessing it through TCP/IP on the same machine).
                  >
                  > Hope this helps.
                  >
                  >
                  > --
                  > - Nicholas Paldino [.NET/C# MVP]
                  > - mvp@spam.guard. caspershouse.co m
                  >
                  > "J" <j@NoSpam.org > wrote in message
                  > news:rdun5199k0 i3jhcg98q1e7g6n rq2f6e8g5@4ax.c om...[color=green]
                  >> Well, the account for the windows service is set to "LocalSyste m", and I
                  >> have
                  >> assigned user id and password for the SQL server connection string.
                  >>
                  >> Any idea?
                  >> Thanks.
                  >>
                  >>
                  >> On Tue, 12 Apr 2005 09:36:03 -0700, "Salvador"
                  >> <Salvador@discu ssions.microsof t.com> wrote:
                  >>[color=darkred]
                  >>>Hi,
                  >>>
                  >>>The first thing that you should notice is that the service uses another
                  >>>account to run, maybe you have a permissions issue. Try to load your
                  >>>server
                  >>>with your user and check again.
                  >>>
                  >>>hope this helps
                  >>>Salva[/color]
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • Willy Denoyette [MVP]

                    #10
                    Re: windows service


                    "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
                    message news:OE8Y6s4PFH A.2136@TK2MSFTN GP14.phx.gbl...[color=blue]
                    > Willy,
                    >
                    > If the SQL server is on another machine, and the service is running
                    > under the Local System account (which doesn't have network access), then
                    > yes, it will be an issue.
                    >
                    > --
                    > - Nicholas Paldino [.NET/C# MVP]
                    > - mvp@spam.guard. caspershouse.co m
                    >[/color]

                    Sorry, but it's not, when using SQL authentication (Integrated Security=
                    false - the default), the SQL server account (User Id and pwd) passed in a
                    connection string is used to authenticate with the SQL server instance, this
                    is how I've been doing for years since the first incarnation of ADO and
                    still doing in .NET.

                    It's also not necessarily true that services running with a "service"
                    account (Local system, network service and local service) can't access
                    network resources. It's true, these accounts don't have network access
                    privileges, the point is that they are not used on the network when
                    authenticating, the machine account is used instead, when this machine
                    account is a AD domain account, it can perfectly be used to authenticate.

                    Willy.




                    Comment

                    • J

                      #11
                      Re: windows service


                      Thanks for everyone's help.

                      Problem solved after I got a user name/password from another programmer which
                      that user name can access network, then I using this user name(account) at 'Log
                      On' tab on my service's properities setting.

                      So here is another question, if windows service and SQL server are in the same
                      machine, do I still need this user name/password to do the task that my service
                      needed to do?
                      Thanks.

                      Comment

                      • Willy Denoyette [MVP]

                        #12
                        Re: windows service


                        "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
                        in message news:egjIGC5PFH A.1528@TK2MSFTN GP09.phx.gbl...[color=blue]
                        > Hi,
                        >
                        > I think that the LocalSystem does has permission to access the network, I
                        > have a couple of processes running as LocalSystem and they listen to and
                        > send/receive data over the network.
                        >
                        > Maybe the OP is running the SQL server with win. auth.
                        >
                        > Why don't you put a try/catch when you open the connection and perform the
                        > DB operations?
                        >
                        > cheers,
                        >
                        > --
                        > Ignacio Machin,
                        > ignacio.machin AT dot.state.fl.us
                        > Florida Department Of Transportation
                        >[/color]

                        No, "Local system" like all the other pseudo accounts, don't have network
                        access privileges, they aren't even used to authenticate as they are no real
                        accounts (they have no password associated).
                        Instead, the system presents the "machine account" domain credentials if it
                        is a W2k/W2K3 domain member when authenticating.
                        That means that a process, running as a pseudo account on a machine called
                        "Alice" in a AD domain called "MyDomain", will use MyDomain\Alice$ when
                        authenticating.
                        The machine account, being just a normal user account, created when adding
                        the machine to the domain, can be used to authenticate against all possible
                        services running in a domain.

                        Don't know about your specific scenario, but Local System was certainly not
                        used to authenticate.

                        Willy.


                        Comment

                        • Willy Denoyette [MVP]

                          #13
                          Re: windows service


                          "J" <j@NoSpam.org > wrote in message
                          news:4r7o51dskt ggta9lcm2tddh5s ouf1a1v2t@4ax.c om...[color=blue]
                          >
                          > Thanks for everyone's help.
                          >
                          > Problem solved after I got a user name/password from another programmer
                          > which
                          > that user name can access network, then I using this user name(account) at
                          > 'Log
                          > On' tab on my service's properities setting.
                          >
                          > So here is another question, if windows service and SQL server are in the
                          > same
                          > machine, do I still need this user name/password to do the task that my
                          > service
                          > needed to do?
                          > Thanks.[/color]

                          You don't need to run your service using the username/password, you have to
                          use this username/password in your Connectionstrin g, again I would like to
                          see your ConnectionStrin g, I guess you did specify "Integrated
                          security=sspi".
                          When both are running on the same machine you can use "integrated security"
                          to connect to SQL server.

                          Willy.


                          Comment

                          • Ignacio Machin \( .NET/ C# MVP \)

                            #14
                            Re: windows service

                            Hi,

                            I was refering to access to the network, not the ability to authenticate on
                            it, I think that if the OP is using SQL authentication and not integrated it
                            should be ok.
                            You can create a TCP connection to a remote host and/or create listening
                            sockets.

                            I do agree with you that the OP problems are probably cause he is using
                            integrated security, now I'm not sure what would happen if the server is
                            configured to use only integrated security what would happen if he does
                            provide the log/pass in the connection string, probably it will not work
                            anyway.

                            cheers,

                            --
                            Ignacio Machin,
                            ignacio.machin AT dot.state.fl.us
                            Florida Department Of Transportation


                            "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                            news:uzHIhO6PFH A.3384@TK2MSFTN GP10.phx.gbl...[color=blue]
                            >
                            > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
                            > wrote in message news:egjIGC5PFH A.1528@TK2MSFTN GP09.phx.gbl...[color=green]
                            >> Hi,
                            >>
                            >> I think that the LocalSystem does has permission to access the network, I
                            >> have a couple of processes running as LocalSystem and they listen to and
                            >> send/receive data over the network.
                            >>
                            >> Maybe the OP is running the SQL server with win. auth.
                            >>
                            >> Why don't you put a try/catch when you open the connection and perform
                            >> the DB operations?
                            >>
                            >> cheers,
                            >>
                            >> --
                            >> Ignacio Machin,
                            >> ignacio.machin AT dot.state.fl.us
                            >> Florida Department Of Transportation
                            >>[/color]
                            >
                            > No, "Local system" like all the other pseudo accounts, don't have network
                            > access privileges, they aren't even used to authenticate as they are no
                            > real accounts (they have no password associated).
                            > Instead, the system presents the "machine account" domain credentials if
                            > it is a W2k/W2K3 domain member when authenticating.
                            > That means that a process, running as a pseudo account on a machine called
                            > "Alice" in a AD domain called "MyDomain", will use MyDomain\Alice$ when
                            > authenticating.
                            > The machine account, being just a normal user account, created when adding
                            > the machine to the domain, can be used to authenticate against all
                            > possible services running in a domain.
                            >
                            > Don't know about your specific scenario, but Local System was certainly
                            > not used to authenticate.
                            >
                            > Willy.
                            >
                            >[/color]


                            Comment

                            Working...