Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 StreamWriter in Script Task

Author  Topic 

infodemers
Posting Yak Master

183 Posts

Posted - 2012-06-14 : 13:10:01
I try to read a file line by line and write to another file some information from the read line in a Script Task from SSIS. When I run the code from my PC it work fine, but when I run it from a schedule job it creates the file but it is always empty.

Any Idea?

Basically this is what I do
Dim strData as String
Dim strLine as String

sr = New System.IO.StreamReader("\\SERVERNAME\RawData\TN\ReadFile.txt", True)
objWriter = New System.IO.StreamWriter("\\SERVERNAME\RawData\TN\Imported.txt", True)

'Read file to collect the necessary data.
Do While sr.Peek() >= 0
strLine = sr.ReadLine()
If CBool(InStr(strLine , "OPM004", CompareMethod.Text)) <> 0 Then
objWriter.WriteLine(strData + Trim(strLine .Substring(9, 6)) & "," &
Trim(strLine .Substring(15, 6)) & "," & Trim(strLine .Substring(21, 6)))
End If
Loop

'Close the file read.
sr.Close()
'Close the write files.
objWriter.Close()[/quote]

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-06-14 : 14:10:06
where is the file being read line by line located at?

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

infodemers
Posting Yak Master

183 Posts

Posted - 2012-06-14 : 14:27:52
from the same location -->\\SERVERNAME\RawData\TN\readfile.txt
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-06-14 : 15:34:53
oops sorry just saw that right there in the code. under whose permissions is the sql job running under and what kind of permissions does it have on that folder \\SERVERNAME\RawData\TN
<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

infodemers
Posting Yak Master

183 Posts

Posted - 2012-06-14 : 15:41:17
I believe the sql job runs under Network Service account and I gave that account full control of the location folder where the file is.

The script creates the file but will not write into it.
Go to Top of Page

infodemers
Posting Yak Master

183 Posts

Posted - 2012-06-22 : 09:40:59
I found the error...

In my code I have the following line...
If CBool(InStr(LigneLue, DateTime.Today.AddDays(-1).ToString("dd/MM/yy"))) <> 0 Then
write someting..
But that condition was never met because the server was still looking at a date format like dd-MM-yy instead of dd/MM/yy/
In the raw data file, the date is like 21/06/12
That was working fine on my PC but not on the server, I have to make it like the following to get it to work.
If CBool(InStr(LigneLue, Replace(DateTime.Today.AddDays(-1).ToString("dd/MM/yy"), "-", "/"))) <> 0 Then
Go to Top of Page
   

- Advertisement -