2

このパッケージを Visual Studio から実行すると正常に動作しますが、SQL エージェント ジョブ (SQL Server 2012 sp1) から実行すると Script Task でエラーがスローされます。SQLエージェントジョブのプロキシアカウントで実行しています。

エラー: ソース: FS ファイル パラメータの設定スクリプト タスクの説明: 呼び出しのターゲットによって例外がスローされました。

プロキシ アカウントは、次のサブシステム用に構成されています。

  • ActiveX スクリプト
  • SQL Server 分析サービス コマンド
  • SQL Server 分析サービス クエリ
  • SQL Server 分析サービス パッケージ
  • パワーシェル

ファイル システムにアクセスしない他のすべてのパッケージは、スクリプト タスクがあっても正常に動作しているため、System.IO を使用するプロキシ アカウントに問題があると思います。すべてのファイル パス変数は、UNC パスで設定されています。フォルダーとファイルには、全員がフル コントロールの構成を持っています。

  • SQL エージェント ジョブから実行するように設定するにはどうすればよいですか?
  • プロキシ アカウントがファイル システムにアクセスできることを確認するにはどうすればよいですか?

スクリプト タスクのコードは次のとおりです。

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

public void Main()
    {
        Dts.Variables["User::AS_FileArchivePath"].Value = "";
        Dts.Variables["User::ExcludeProvidersArchivePath"].Value = "";
        Dts.Variables["User::AS_FilePath"].Value = "";
        Dts.Variables["User::ExcludeProvidersFilePath"].Value = "";
        Dts.Variables["User::FeeScheduleFileName"].Value = "";
        Dts.Variables["User::FileArchivePath"].Value = "";


        //get load file name
        String dirPath = Dts.Variables["User::FileDropFolder"].Value.ToString();
        String fileExt = Dts.Variables["User::LoadFileExt"].Value.ToString();
        String FileArchivePath =    Dts.Variables["User::FileArchiveFolder"].Value.ToString() + Dts.Variables["User::FileArchiveDateFolder"].Value.ToString();
        String FileName = "";
        String FileType = "";
        int FileSize = 0;
        DirectoryInfo dir = new DirectoryInfo(dirPath);

        foreach (FileInfo file in dir.GetFiles())
        {
            if (file.Extension.Contains(fileExt)
                && file.Name.StartsWith("DoNotDeleteTemplate") == false
                && file.Name.Contains("Products") == true
                && file.Name.Contains("Special") == false
                && file.Name.Contains("Exclude") == false)
            {
                FileName = file.Name;
                FileSize = (int)file.Length;
                FileType = file.Extension;
            }
        }


        if (FileName != "")
        {
            Dts.Variables["User::FeeScheduleFileName"].Value = FileName;
            Dts.Variables["User::FeeScheduleFileSize"].Value = FileSize;
            Dts.Variables["User::FeeScheduleFileType"].Value = FileType;

            //create archive folder
            bool folderExists = Directory.Exists(FileArchivePath);
            if (!folderExists)
                Directory.CreateDirectory(FileArchivePath);

            //set full archive path
            Dts.Variables["User::FileArchivePath"].Value = FileArchivePath + "\\" + FileName;


            //set full load file path
            String filePath = Dts.Variables["User::FileDropFolder"].Value.ToString() + FileName;

        }

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

0 に答える 0