【问题标题】:Can not read the flat file source无法读取平面文件源
【发布时间】:2014-02-19 10:45:22
【问题描述】:

我想从用户那里得到文件名,然后根据那个名字我会得到另一个输入。这是一个多输入多输出问题。 所以我将问题归一化如下。

1.我在控制流中使用脚本测试并要求使用 C# 中的表单输入文件名。我在浏览文件时得到文件名。

2.然后解压文件并根据我设置的文件名检查文件名 3个变量是globel。

3.根据变量我做了3个数据流任务。并且对于上述指定的问题效果很好。

4.它适用于不同的数据流任务。

但是当我动态使用平面文件源名称(使用表达式)时,我遇到了另一个问题,它给了我关于无法打开文件的错误。

错误“[平面文件源 [1]] 错误:无法打开数据文件“C:\Documents and Settings\XQN4P\Desktop\Inputs\Intraday\OPTION_DAILY_INTRADAY_ASIA20140212.csv”。“

请注意,此文件是通过用户解压缩输入的文件生成的。

还有警告 "[Flat File Source [1]] 警告:该进程无法访问该文件,因为它正被另一个进程使用。 "

这是我用来解压的代码。

}
private void unzipInFile(string inputFilePath, string destDirectory,string destFileName)
{
    FileStream fsIn  =new FileStream (inputFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
    FileStream fsOut =new FileStream(destDirectory +"\\"+destFileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
     int  buffersize = 4096;
    int count = 0;
    var   buffer= new byte [buffersize]; 
    //using (Stream compressed = File.OpenRead(inputFilePath))
    //using (ZlibStream zlib = new ZlibStream(compressed, CompressionMode.Decompress))
    using(GZipStream gZip  = new GZipStream(fsIn, Ionic.Zlib.CompressionMode.Decompress, Ionic.Zlib.CompressionLevel.BestCompression, true ))

    {
        byte[] buf = new byte[short.MaxValue];
        int bufl;
        while (0 != (bufl = gZip.Read(buf, 0, buf.Length)))
        {
            if (count != 0) 
                fsOut.Write(buffer, 0, count);
            if (count != buffersize)
                 return ;
        }
    }
    fsOut.Close();


}

另一个地址变量

Dts.Variables["FileAddress"].Value = filePath + ".csv";

SSIS 结构: “ScriptTask”将输出发送到 3 个数据流任务。

【问题讨论】:

  • 你可以在这里发布一些代码
  • 嗨,我认为问题在于解压缩文件,因为我检查了文件是空的。当我跳过解压缩并将提取的文件放在那里时,它正在工作。但是我对解压缩功能感到惊讶,为什么它不能在另一个功能中工作..

标签: c# ssis c#-3.0


【解决方案1】:

问题已解决。 问题在于解压缩文件的格式。 它无法获取行分隔符。 有时文件仍在使用中。 所以我解决了这个问题,没关系

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 2018-11-12
    • 2014-06-07
    • 1970-01-01
    • 2016-10-21
    相关资源
    最近更新 更多