2016-10-28 8 views
2

デバッグできない単純なスクリプトを作成しました。 Visual Studio 2015でSSISの変数にディレクトリの内容を保存しようとしています。C#スクリプトのSSISオブジェクト変数に影響するタスク

私のSSISパッケージに変数を作成し、そのデータ型をObjectに設定しました。 は、私はこのコードが含まれている私のパッケージスクリプトタスクに追加しました:

#region Namespaces 
using System; 
using System.Data; 
using Microsoft.SqlServer.Dts.Runtime; 
using System.Windows.Forms; 
using System.IO; 
using System.Collections.Generic; 
#endregion 

namespace ST_c6399821104c42c2859b7b2481055848 { 

[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute] 
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase { 

    public void Main() { 

     string CSVFilesCompletePath; 

     if (Dts.Variables.Contains("User::CSVFilesPathAbsolute") == true 
      && Dts.Variables.Contains("User::CSVFilesPathRelativeCountry") == true 
      && Dts.Variables.Contains("User::CSVFilesCountryObject") == true) { 

      CSVFilesCompletePath = Dts.Variables["User::CSVFilesPathAbsolute"].ToString() + Dts.Variables["User::CSVFilesPathRelativeCountry"].ToString(); 


      String[] fileListTable = Directory.GetFiles(CSVFilesCompletePath, "*.xlsx"); 
      List<string> fileList = new List<string>(fileListTable); 
      Dts.Variables["User::CSVFilesCountryObject"].Value = fileList; 
     } 

     Dts.TaskResult = (int)ScriptResults.Success; 

    } 
    #region ScriptResults declaration 
    /// <summary> 
    /// This enum provides a convenient shorthand within the scope of this class for setting the 
    /// result of the script. 
    /// 
    /// This code was generated automatically. 
    /// </summary> 
    enum ScriptResults 
    { 
     Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, 
     Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure 
     }; 
     #endregion 
    } 
} 

としては、ここで説明: SSIS Script Task Get File Names and Store to an SSIS Object Variable

をしかし、私はSSISを通してそれを起動しようとすると、このコードは、次のエラーを返します求人:

SSIS C# Script Error

変数が正しくReadWriteVariablesとしてスクリプトウィザードで設定されています。

問題は、SSIS変数に影響を与えて、String[]を入力しようとすると、このエラーが表示されることです。

Directory.GetFiles 

コールまたは全身ででのtry-catchを追加

+0

私はSSISをやってからしばらくしていましたが、スクリプトで書き込み可能な変数を設定する必要があることを覚えているようです。あなたはそれをやりました? – AgapwIesu

+0

はい、私の記事の一番下にあるように、私はスクリプトタスクウィザードでReadWriteVarialbeとして変数を設定しました –

+0

残念です。 – AgapwIesu

答えて

0

私にエラーが発生しました:

CSVFilesCompletePath = Dts.Variables["User::CSVFilesPathAbsolute"].ToString() + Dts.Variables["User::CSVFilesPathRelativeCountry"].ToString(); 

は、私が使用することをhade Variableの内容の代わりにVariableのGetFilesがnullオブジェクトを返しました。これを変数に格納して別のエラーを作成することはできませんでした。

1

てみてください、そして、デバッグ目的のために書き込みSSIS変数にエラーメッセージおよび/または例外のスタックトレースを設定します。

編集:@ H.Fadlallahのように見えますが、問題を指摘しています。私は名前を使用していたとしてDts.Variables[].Value.ToString()代わりDts.Variables[].ToString()

の:あなたはDtsVariableのValueプロパティを使用する必要があり、ないのToString()

+0

こんにちは、答えのおかげで。私は 'e'という例外を除いて、' catch {} 'ステートメントの変数にメッセージを格納しようとしました。次に、次のコードで変数を設定しようとしました。 'Dts.Variables [" User :: Error "]。値= e.Message;' SSISジョブによって同じエラーが返されます。 SSIS変数に値を格納できる何かが恋しくなるようです。 –

関連する問題