Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 从sql代理作业运行ssis脚本任务时引发错误_Sql Server_Ssis_Sql Server 2012 - Fatal编程技术网

Sql server 从sql代理作业运行ssis脚本任务时引发错误

Sql server 从sql代理作业运行ssis脚本任务时引发错误,sql-server,ssis,sql-server-2012,Sql Server,Ssis,Sql Server 2012,当我从Visual Studio运行此包时,它工作正常,但当我从sql代理作业(sql Server 2012 sp1)运行它时,它会在脚本任务上抛出错误。我在sql代理作业中的代理帐户下运行它 错误:源:设置FS文件参数脚本任务描述:调用目标引发异常 已为以下子系统配置代理帐户: ActiveX脚本 SQL Server分析服务命令 SQL Server分析服务查询 SQL Server分析服务包 动力壳 我猜这是使用System.IO的代理帐户的问题,因为所有其他不访问文件系统的包都运行

当我从Visual Studio运行此包时,它工作正常,但当我从sql代理作业(sql Server 2012 sp1)运行它时,它会在脚本任务上抛出错误。我在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;
    }

您是否检查了要读取/写入的文件服务器上的eventviewer?还可以尝试在脚本上放置try/catch块,以便查看详细错误。在Visual Studio中工作,不作为作业工作?除具有文件访问权限的包以外的所有包都可以工作吗?尽管看起来用户访问设置正确。。事实并非如此。如果您想要暴力解决方案,请使用ProcMon确定哪个文件/文件夹存在访问问题。我执行了以下操作:打开组件服务,展开组件服务->我的计算机->DCOM配置,找到“Microsoft SQL Server Integration Services 11.0”Rt单击并选择“属性”选择“安全”选项卡,在启动和激活权限中,然后“编辑”授予SQL代理服务/代理帐户MyDomain\MyAcct的“本地启动”、“本地激活”权限,重新启动SQL代理并重试,现在事件查看器中的错误消失,但是我仍然在sysssislog中得到错误:Source:Set FS File Parameters Script Task:Exception已被调用的目标抛出。我正在失去希望,请响应。我相信很多人都在他们的ETL中使用它。谢谢。当我使用服务帐户在SQL代理中的计划作业中运行包时,我收到了此错误。我将脚本任务中的代码包装在一个try-catch块中,并将错误消息复制到下面。我已将所有人都设置为完全控制E-drive上的文件夹。错误消息:以用户身份执行:MyDomain\MyServiceAcct。Microsoft(R)SQL Server Execute Package Utility版本11.0.2100.60,适用于32位版权来源:Set-FSFileParameters脚本任务我的文件任务描述:拒绝访问路径“\\MyServer\E$\MyFiles\FSP\”。结束错误DTExec:包执行返回DTSER_失败(1)。