Question : .net Windows Service - access to folder on LAN is denied

Hi,

I just created a windows service (as per below) which simply copies a file every 10 seconds (I will change that to just once a day... just want to backup a file on the server onto the LAN). I changed the ip address just to 'ipaddress' but the error message below leads me to think that it can find the file ok, but I just can't access it as my access to that folder is denied. The code works fine when i copy to my local pc but just not when trying to copy from local pc to LAN.

I did read, however, that windows services run under the system account and don't have access to the network. If so, how to gain access... or how to achieve what i want to achieve?

error message: (not too sure what first part is... something missing i guess for my computer to be able to display it.

The description for Event ID ( 0 ) in Source ( Application ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Copy Failed: Access to the path '\\10.237.47.143\DEPT\CSO\OBO\BRA\BRA\Sita Account\Aiden\TestLAN\CTA Test.mdb' is denied..


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
Imports System.Timers
Imports System.IO
Imports System.Net

Public Class CSATService
   Private t As Timer = Nothing

   Protected Overrides Sub OnStart(ByVal args() As String)
      ' Add code here to start your service. This method should set things
      ' in motion so your service can do its work.

      t.Start()

   End Sub

   Protected Overrides Sub OnStop()
      ' Add code here to perform any tear-down necessary to stop your service.
      t.Stop()
   End Sub

   Protected Sub t_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)

      Try
         Dim copyFile As FileInfo = New FileInfo("E:\Test\CTA Test 2010.06.30.mdb")
         copyFile.CopyTo("\\ipaddress\TestLAN\CTA Test.mdb", True)
      Catch ex As Exception
         System.Diagnostics.EventLog.WriteEntry("Application", "Copy Failed: " & ex.Message.ToString)
      End Try

   End Sub

   Public Sub New()

      ' This call is required by the Windows Form Designer.
      InitializeComponent()

      ' Add any initialization after the InitializeComponent() call.
      t = New Timer(10000)
      AddHandler t.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf t_Elapsed)

   End Sub
End Class

Answer : .net Windows Service - access to folder on LAN is denied

Sorry, I thought it was a sql server datafile. In case of an Access datafile, you can ignore the points about not being able to copy and backup job. But it could still be a problem with the file being in use.

But if the service is running with the system account, that is probably the cause. This account doesn't have access on the lan. It doesn't matter whether your own user has access or not. You can change user under Logon properties for the service.

Random Solutions  
 
programming4us programming4us