Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Curious Problem..

Reply
Thread Tools

Curious Problem..

 
 
Rob Meade
Guest
Posts: n/a
 
      04-25-2004
Hi all,

I have written a small windows service which checks a directory for a new
file, upon receiving one writes a line to the log file and then copies the
file to SQL server.

I've had a few problems with it today, so have been running it in debug
mode - when I do so and step through its all perfect - no problems at all -
as soon as I remove the debugger.launch() line and run the service - whilst
it doesn't error, the database end seems to fail, ie, no new row is
written..

Can anyone suggest what might be wrong here? The service is using a
database connection which specifies the user id and password to use on the
database, so my initial though of "oh it must be permissions" may well be
wrong...

The service is running under the LocalSystem account.

If anyone has any ideas I'd love to hear from you...this has gone quite well
thus far but cant really run it in debug mode for ever! )

Thanks in advance for any help - will post code if applicable.

Regards

Rob


 
Reply With Quote
 
 
 
 
Chris Botha
Guest
Posts: n/a
 
      04-26-2004
Rob, it may be a security problem, especially if the directory is a network
drive. I'm not sure, but attaching the debugger may run the service as the
interactive user. A quick test should be to run the service as your own
login, rather than the local system account, and see if it works then.

"Rob Meade" <(E-Mail Removed)> wrote in message
news:EpWic.1589$(E-Mail Removed)...
> Hi all,
>
> I have written a small windows service which checks a directory for a new
> file, upon receiving one writes a line to the log file and then copies the
> file to SQL server.
>
> I've had a few problems with it today, so have been running it in debug
> mode - when I do so and step through its all perfect - no problems at

all -
> as soon as I remove the debugger.launch() line and run the service -

whilst
> it doesn't error, the database end seems to fail, ie, no new row is
> written..
>
> Can anyone suggest what might be wrong here? The service is using a
> database connection which specifies the user id and password to use on the
> database, so my initial though of "oh it must be permissions" may well be
> wrong...
>
> The service is running under the LocalSystem account.
>
> If anyone has any ideas I'd love to hear from you...this has gone quite

well
> thus far but cant really run it in debug mode for ever! )
>
> Thanks in advance for any help - will post code if applicable.
>
> Regards
>
> Rob
>
>



 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      04-26-2004
"Chris Botha" wrote ...

> Rob, it may be a security problem, especially if the directory is a

network
> drive. I'm not sure, but attaching the debugger may run the service as the
> interactive user. A quick test should be to run the service as your own
> login, rather than the local system account, and see if it works then.


Hi Chris,

I can confirm that it isnt a network drive - I have one server running both
Windows Server 2003 and SQL Server 2000 as a dev box.

I will try the login idea you suggested - *if* it does then work as it
should - what am I going to need to do to make it work? As I mentioned the
only part failing was the SQL update - which confused me considering I was
specifying the user/pwd to use for that in the code..

Any further info would be appreciated,

Regards

Rob


 
Reply With Quote
 
Chris Botha
Guest
Posts: n/a
 
      04-26-2004
> As I mentioned the only part failing was the SQL update - which confused
me considering
> I was specifying the user/pwd to use for that in the code


Rob, I saw this, and is why I thought you may be barking up the wrong tree.
Why are you so sure it is the SQL failing? What is your connection string?

"Rob Meade" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "Chris Botha" wrote ...
>
> > Rob, it may be a security problem, especially if the directory is a

> network
> > drive. I'm not sure, but attaching the debugger may run the service as

the
> > interactive user. A quick test should be to run the service as your own
> > login, rather than the local system account, and see if it works then.

>
> Hi Chris,
>
> I can confirm that it isnt a network drive - I have one server running

both
> Windows Server 2003 and SQL Server 2000 as a dev box.
>
> I will try the login idea you suggested - *if* it does then work as it
> should - what am I going to need to do to make it work? As I mentioned the
> only part failing was the SQL update - which confused me considering I was
> specifying the user/pwd to use for that in the code..
>
> Any further info would be appreciated,
>
> Regards
>
> Rob
>
>



 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      04-26-2004
"Chris Botha" wrote ...

> Rob, I saw this, and is why I thought you may be barking up the wrong

tree.
> Why are you so sure it is the SQL failing? What is your connection string?


Hi Chris,

Thanks again for the reply.

Well, when I say 'failing' maybe thats not the correct phrase as it clearly
is ok in debug mode - the reason I know its not 'firing' (for want of a
better word) is that no row is being written to the database..

I've cleared the table right down, I can run the service, test it a couple
of times, I get 2 rows in the event log, 2 rows in the database, then I
switch off the debug mode and run it again - 1 row in the event log - no
rows added to the database..

Connection string is:

strConnection = "user id=testservice;data source=""TITUS\KWS"";initial
catalog=testservice; password=testservice"

the entire database bit of my code looks like this:

' Declare variables
Dim objConnection As SqlConnection
Dim objCommand As SqlCommand
Dim strConnection As String
Dim strSQL As String

' Define connection string
strConnection = "user id=*******;data source=""TITUS\KWS"";initial
catalog=testservice; password=*******"

' Create and open our database connection
objConnection = New SqlConnection(strConnection)
objConnection.Open()

' Generate SQL statement
strSQL = "exec storeEmail" & " '" & strStream & "' "

' Execute command
objCommand = New SqlCommand(strSQL, objConnection)
objCommand.ExecuteNonQuery()

' Close and clear our objects
objCommand.Dispose()
objCommand = Nothing
objConnection.Close()
objConnection = Nothing


Any thoughts?

Regards

Rob


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      04-26-2004
"Chris Botha" wrote...

> A quick test should be to run the service as your own
> login, rather than the local system account, and see if it works then.


In visual studio upon clicking on the ProjectInstall.vb file I can then
click on the ServiceProcessInstaller1 and there is a property named
account - the only options are:

Local Service
Network Service
Local System
User

It was running with local system before, I have tried User this evening,
however you are unable to pre-populate this with any user details - instead
when I try to install it it then prompts for the details - upon doing so the
install failed..

?

Rob


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      04-26-2004
"Chris Botha" wrote ...

> A quick test should be to run the service as your own
> login, rather than the local system account, and see if it works then.


I see what you mean now sorry - my fault, you meant under the administrative
tools/ services change the user - I've done that change it to 'my' NT Login
and now it works fine....

Erm...what does this mean then?

Regards

Rob


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      04-26-2004
>I've done that change it to 'my' NT Login
> and now it works fine....


That would actually appear to be an exaggeration - it worked ONCE - I then
sent another email through and the event log updated, but the database
didn't...

I've tried restarting the service and still the same problem - the table in
SQL Server is not getting update?!

This isn't quite going to plan.. /

Rob


 
Reply With Quote
 
Chris Botha
Guest
Posts: n/a
 
      04-26-2004
Rob, your connection string looks good. Add a test piece to your service to
insert a test record in a test table (run this code first before anything
else, so if something fails it does not effect the test code), to confirm
your database access works.
If this works, write a test piece to delete a dummy file from the directory,
insert the code right after the SQL server test piece, to confirm you have
access to the directory.

To run a service as a specific user (you don't use Visual Studio), open
control panel, go to services, find your service, right-click, then
properties, then the Log On tab, and change the user. Ensure that you
stop/start the service.

"Rob Meade" <(E-Mail Removed)> wrote in message
news:dUajc.2313$(E-Mail Removed)...
> "Chris Botha" wrote...
>
> > A quick test should be to run the service as your own
> > login, rather than the local system account, and see if it works then.

>
> In visual studio upon clicking on the ProjectInstall.vb file I can then
> click on the ServiceProcessInstaller1 and there is a property named
> account - the only options are:
>
> Local Service
> Network Service
> Local System
> User
>
> It was running with local system before, I have tried User this evening,
> however you are unable to pre-populate this with any user details -

instead
> when I try to install it it then prompts for the details - upon doing so

the
> install failed..
>
> ?
>
> Rob
>
>



 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      04-26-2004
"Chris Botha" wrote ...

> Rob, your connection string looks good.


Thank you

> Add a test piece to your service to insert a test record in a test table

(run this code first before anything
> else, so if something fails it does not effect the test code), to confirm
> your database access works.


okey dokey - I'll copy the database code and dump it at the top and just
write a single entry that means something here etc..

> If this works, write a test piece to delete a dummy file from the

directory,
> insert the code right after the SQL server test piece, to confirm you have
> access to the directory.


I will but I'm 100% sure that I have access to the directory- because the
code returns the full path to the file that has just been created/deleted
and writes that to the event log - I'll do it anyway..

Will do this now and post back in a bit - thanks for the continued help

Rob


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
just curious Mike Roberts Wireless Networking 0 11-28-2005 04:31 AM
Curious article for Linksys router wrt54GS Frank Wireless Networking 0 07-03-2005 05:04 PM
just curious whitzombi Firefox 2 11-09-2004 03:37 AM
Curious Ed Mullen Firefox 34 03-02-2004 11:34 PM
A curious behaviour with an URL on the W3C Griffure Firefox 0 08-11-2003 11:46 AM



Advertisments