我有一个SSIS程序包,其中有一个脚本任务。我有以下代码,正在尝试解压缩文件
string subPath = Dts.Variables["User::ProcessingFolder"].Value.ToString();
bool exists = System.IO.Directory.Exists(subPath);
if (!exists)
System.IO.Directory.CreateDirectory(subPath);
string zipFilename = Dts.Variables["User::varProcessingFile"].Value.ToString();
string targetDirectory = subPath;
ZipFile.ExtractToDirectory(zipFilename, subPath);
Dts.TaskResult = (int)ScriptResults.Success;
以上代码在Visual Studio中有效,但是在通过SQL Agent运行时,不会发生解压缩。
如何解决此问题?
我认为您面临权限问题,因为当您从Visual Studio运行程序包时,该程序包将由当前用户执行,但是当您从SQL代理程序执行时,它将使用SQL Server服务帐户。
为了解决此问题,您必须授予服务帐户访问所有所需目录的权限,或者必须以代理用户身份执行软件包: