从sql代理作业运行时,ssis脚本任务抛出错误

时间:2013-11-14 19:58:33

标签: sql-server ssis sql-server-2012

当我从Visual Studio运行此包时,它工作正常,但是当我从sql代理作业(SQL Server 2012 sp1)运行它时,它会在脚本任务上抛出错误。我在sql代理作业中的代理帐户下运行它。

  

错误:源:设置FS文件参数脚本任务描述:调用目标已抛出异常。

为以下子系统配置代理帐户:

  • ActiveX脚本
  • SQL Server Analysis Services命令
  • SQL Server Analysis Services查询
  • SQL Server Analysis Services包
  • PowerShell的

我想使用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;
    }

0 个答案:

没有答案