首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SSIS用脚本追加预告片

SSIS用脚本追加预告片
EN

Database Administration用户
提问于 2015-01-27 13:57:40
回答 1查看 1.1K关注 0票数 2

我试图添加一个页脚到一个平面文件输出。我的控制流中有两个数据流。一个是从DB创建文件。它从OLE DB Source到平面文件目的地。第二控制流使用指向与第一数据流相同的文件路径的第二连接管理器,并使用。在第二个数据流中,我使用指向平面文件的脚本组件来追加预告片。

问题是脚本没有生成任何输出。我是一个C#新手,已经修改了在网上找到的代码,并希望得到任何帮助。

以下是C#2012中的code代码:

代码语言:javascript
复制
[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();

     }
 }
EN

回答 1

Database Administration用户

发布于 2015-01-27 16:26:36

我不得不在Control流级别使用脚本任务,而不是在数据流级别使用脚本组件。当我把它换过来的时候,它就像一种魅力。我还将sw.Write(fileText, System.Text.Encoding.ASCII);行更改为sw.WriteLine(fileText, System.Text.Encoding.ASCII);,以便将文本添加到下一行。

票数 1
EN
页面原文内容由Database Administration提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://dba.stackexchange.com/questions/90305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档