我试图添加一个页脚到一个平面文件输出。我的控制流中有两个数据流。一个是从DB创建文件。它从OLE DB Source到平面文件目的地。第二控制流使用指向与第一数据流相同的文件路径的第二连接管理器,并使用。在第二个数据流中,我使用指向平面文件的脚本组件来追加预告片。
问题是脚本没有生成任何输出。我是一个C#新手,已经修改了在网上找到的代码,并希望得到任何帮助。
以下是C#2012中的code代码:
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public void Main()
{
const string dirPath = @"Q:\General\Operations\Prod_Support\XOOM OPS Procedures\Wells_Testing\";
var fileBody = AddHeaderAndFooter.GetFileText(dirPath + "WellsPOS.txt");
var trailerRecord = "9" + DateTime.Today.ToString("ddMMyyyy") + AddHeaderAndFooter.CountRecords(dirPath + "WellsPOS.txt").ToString();
var outPutData = fileBody + trailerRecord + "\r\n";
AddHeaderAndFooter.WriteToFile(dirPath + "WellsPOS.txt", outPutData);
}
}
public static class AddHeaderAndFooter
{
public static int CountRecords(string filePath)
{
return (System.IO.File.ReadAllLines(filePath).Length + 2);
}
public static string GetFileText(string filePath)
{
var sr = new System.IO.StreamReader(filePath, System.Text.Encoding.Default);
var recs = sr.ReadToEnd();
sr.Close();
return recs;
}
public static void WriteToFile(string filePath, string fileText)
{
var sw = new System.IO.StreamWriter(filePath, false);
sw.Write(fileText, System.Text.Encoding.ASCII);
sw.Close();
}
}发布于 2015-01-27 16:26:36
我不得不在Control流级别使用脚本任务,而不是在数据流级别使用脚本组件。当我把它换过来的时候,它就像一种魅力。我还将sw.Write(fileText, System.Text.Encoding.ASCII);行更改为sw.WriteLine(fileText, System.Text.Encoding.ASCII);,以便将文本添加到下一行。
https://dba.stackexchange.com/questions/90305
复制相似问题