Occasionally the script task fails with this error message:
The script threw an exception: Access to the path 'C:\path\flatfile.txt' is denied.
Here is the code of my script:
Public Sub Main()
'
' Add your code here
'
Dim vars As Variables
Dts.VariableDispenser.LockOneForRead("User::FullFilePath", vars)
Dim filepath As String = vars("FullFilePath").Value.ToString()
vars.Unlock()
Dim file As File
Dim reader As StreamReader
reader = file.OpenText(filepath)
Dim line As String
line = reader.ReadLine()
reader.Close()
'MsgBox(line.Substring(29))
Dim asofdate As String
asofdate = line.Substring(29, 5)
asofdate = asofdate + "20" + line.Substring(34)
'MsgBox(asofdate)
Dim writeVars As Variables
Dts.VariableDispenser.LockOneForWrite("User::AsOfDate", writeVars)
writeVars(0).Value = asofdate
'MsgBox("done")
writeVars.Unlock()
Dts.TaskResult = Dts.Results.Success
End Sub
Does anyone see anything that I'm not. I believe i'm closing all necessary resources and streams. Does anyone have suggestions.
Thank you very much in advance.
Is it possible that your service calls the package multiple times simultaneously, or that the package could be executed before the drop is completed? The access violation in either of those cases would be due to the file still being locked by something else (e.g. the process writing the file, or the first package processing the file).
If neither are the case, then you could try a small re-write to see if it helps:
Replace:
Dim file As File
Dim reader As StreamReader
reader = file.OpenText(filepath)
Dim line As String
line = reader.ReadLine()
reader.Close()
With:
Dim line As String
Using reader as new StreamReader(filepath)
line = reader.Readline()
reader.Close()
End Using
HTH,
Patrik
|||Thanks for your response.After banging my head against the table for a day i realized that the reason I was having issues is because the package in question was running as a service. The service was running under a particular user or usergroup. This usergroup was not one that had access to the files being run through my package, and therefore the package had its access deined by the OS.
In the interest of helping others, I'll leave this post up, even though it should have been one of the first things I tried.
No comments:
Post a Comment