在单个分配中分配的值不止一次

时间:2016-12-15 13:32:21

标签: c# ssis

我制作了一个脚本任务,使用文件ID和准备好的URL地址从Google云端硬盘下载并保存在磁盘上的两个电子表格。

这是我的C#代码中的main(),除此之外没有任何东西:

   public void Main()
    {
        string m_FileId = Dts.Variables["User::varFileId"].Value.ToString();
        string m_RemoteUrl = "https://docs.google.com/spreadsheets/d/" + m_FileId + "/export?format=xlsx";
        string m_FilePath = null;


        WebClient client = new WebClient();


        try
        {
            m_FilePath = Dts.Variables["User::varFilePath"].Value.ToString() + Dts.Variables["User::varFileName"].Value.ToString();
            client.DownloadFile(new System.Uri(m_RemoteUrl), m_FilePath);
            m_FilePath = "";

            m_FileId = Dts.Variables["User::varFileId2"].Value.ToString();
            m_RemoteUrl = "https://docs.google.com/spreadsheets/d/" + m_FileId + "/export?format=xlsx";
            m_FilePath = Dts.Variables["User::varFilePath"].Value.ToString() + Dts.Variables["User::varFileName2"].Value.ToString();

            client.DownloadFile(new System.Uri(m_RemoteUrl), m_FilePath);
        }
        catch(Exception e)
        {
            Dts.Events.FireError(0, "FileDownload", e.Message 
                                                    + "\r" + e.StackTrace 
                                                    + " \rUrl: " + m_RemoteUrl 
                                                    + " \rFilePath: " + m_FilePath 
                                                    + " \rPath: " + Dts.Variables["User::varFilePath"].Value.ToString()
                                                    + " \rFileName2: " + Dts.Variables["User::varFileName2"].Value.ToString()
                                                    , string.Empty, 0);
            Dts.TaskResult = (int)ScriptResults.Failure;
        }

        Dts.TaskResult = (int)ScriptResults.Success;
    }

问题恰好发生在每次运行此代码时,我都不知道如何摆脱它。我的脚本任务中只有例外。我打印了此代码中使用的所有变量,正如您可以看到m_FilePath出现问题,尽管只打印了一次,但它仍然成倍增加。

[FileDownload] Error: An exception occurred during a WebClient request.
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at ST_84b63d1593dd449886eb2b32dff40b2d.ScriptMain.Main() 
Url: https://docs.google.com/spreadsheets/d/----------/export?format=xlsx 
FilePath: C:\Google Drive extract\ga_manual_cost_file.xlsxC:\Google Drive extract\ga_manual_cost_file.xlsx 
Path: C:\Google Drive extract\ga_manual_cost_file.xlsx 
FileName2: ga_manual_cost_file.xlsx

我使用的SSIS变量是ReadOnly,仅在此脚本任务中使用(我尝试仅运行此部分控制流),其值如下:

variables

0 个答案:

没有答案