I'm using SSIS in Visual Studio 2019 to read fixed width text files. Depending on the first character of each row in the fixed width file, I'm sending the line to one of two specified outputs. Both outputs are configured with a length of 700, matching the text file fixed width.
The Script Component is programmed using C# and evaluates the first character of each line using a pair of if/else statements.
My question: the script provided below builds and the SSIS package runs successfully but writes 0 rows to the tables in the database. I think the root cause is calling line.Split(delimiters) and need guidance as to how to remedy the issue.
public class ScriptMain : UserComponent
{
private StreamReader textReader;
private string rxFile;
private string stagingPath = "mypath";
private char[] delimiters;
public override void AcquireConnections(object Transaction)
{
IDTSConnectionManager100 connMgr = this.Connections.TransactionFile;
rxFile = (string)connMgr.AcquireConnection(null);
}
public override void PreExecute()
{
base.PreExecute();
textReader = new StreamReader(rxFile);
}
public override void CreateNewOutputRows()
{
DirectoryInfo di = new DirectoryInfo(stagingPath);
FileInfo[] files = di.GetFiles("*.txt");
foreach (FileInfo file in files)
{
using (FileStream fileStream = file.OpenRead())
using (textReader)
{
while (!textReader.EndOfStream)
{
string line = textReader.ReadLine();
delimiters = Environment.NewLine.ToCharArray();
string[] items = line.Split(delimiters);
if (items[0] == "2")
{
PharmacyBuffer.AddRow();
PharmacyBuffer.Column0 = items[0];
}
else if (items[0] == "4")
{
TransactionsBuffer.AddRow();
TransactionsBuffer.Column0 = items[0];
}
}
}
}
textReader.Close();
textReader.Dispose();
}
public override void PostExecute()
{
base.PostExecute();
}
}
string[] itemscontain the values you expect? Are the conditional statements associated with the content ofitemsflowing as you expect? And finally, when you add a result viewer or test variable to inspect the output of this script task, does it contain the results you expect? Please edit your question and provide more debugging details like this.fileStream(no usages) andtextReader(only the transaction file)?