windows service

  • Thread starter Thread starter J
  • Start date Start date
J

J

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.
 
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
 
Well, the account for the windows service is set to "LocalSystem", and I have
assigned user id and password for the SQL server connection string.

Any idea?
Thanks.
 
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.
 
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
 
Nicholas Paldino said:
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.

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

Willy.
 
J said:
Well, the account for the windows service is set to "LocalSystem", and I
have
assigned user id and password for the SQL server connection string.

Any idea?
Thanks.

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

Willy.
 
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.
 
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 said:
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]
- (e-mail address removed)

J said:
Well, the account for the windows service is set to "LocalSystem", and I
have
assigned user id and password for the SQL server connection string.

Any idea?
Thanks.
 
Nicholas Paldino said:
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.

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.
 
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.
 
Ignacio Machin ( .NET/ C# MVP ) said:
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,

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.
 
J said:
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.

You don't need to run your service using the username/password, you have to
use this username/password in your Connectionstring, again I would like to
see your ConnectionString, 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.
 
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
 
Back
Top