SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 StreamWriter in Script Task
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

infodemers
Posting Yak Master

Canada
166 Posts

Posted - 06/14/2012 :  13:10:01  Show Profile  Reply with Quote
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]

Edited by - infodemers on 06/14/2012 16:31:38

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 06/14/2012 :  14:10:06  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
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

Canada
166 Posts

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

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 06/14/2012 :  15:34:53  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
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

Canada
166 Posts

Posted - 06/14/2012 :  15:41:17  Show Profile  Reply with Quote
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

Canada
166 Posts

Posted - 06/22/2012 :  09:40:59  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000