我正在尝试从我自己工作的 C# 运行 SSIS 包。我遇到的问题是我想让用户即时设置包。我设置了一个似乎正在工作的模拟类,但是当从 IIS 运行该包时会抛出错误。但是,当我从 VS2010 调试运行它时,它确实有效。
using (ImpersonatedUser iu = new ImpersonatedUser("username", "domain", "password"))
{
Application app = new Application();
Package package = null;
MyEventListener eventListener = new MyEventListener();
app.PackagePassword = "packagepassword";
package = app.LoadPackage(@"packagepath", null);
Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute(null, null, eventListener, null, null);
if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
{
foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in package.Errors)
{
lblErrorOutput.Text += "<br />Package Execution results: " + local_DtsError.Description.ToString();
lblErrorOutput.Text += eventListener.output;
}
}
else
{
lblErrorOutput.Text = WindowsIdentity.GetCurrent().Name;
lblErrorOutput.Text += eventListener.output;
}
}
这是从调试运行时的输出,然后是从 IIS 运行时(在同一台计算机上)
domain\user
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Validation phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Validation phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Prepare for Execute phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Pre-Execute phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/Source File [1] : The processing of file "filepathandname.csv" has started.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Validation phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Prepare for Execute phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Pre-Execute phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/Flat File Destination [16] : The processing of file "filepathandname.csv" has started.
然后当通过 IIS
domain\user
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Validation phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Validation phase is beginning.
Error in: Microsoft.SqlServer.Dts.Runtime.Package/Connection manager "SourceConnectionFlatFile" : The file name property is not valid. The file name is a device or contains invalid characters.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Prepare for Execute phase is beginning.
Error in: Microsoft.SqlServer.Dts.Runtime.Package/Connection manager "SourceConnectionFlatFile" : The file name property is not valid. The file name is a device or contains invalid characters.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Pre-Execute phase is beginning.
Error in: Microsoft.SqlServer.Dts.Runtime.Package/Connection manager "SourceConnectionFlatFile" : The file name property is not valid. The file name is a device or contains invalid characters.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : Execute phase is beginning.
Information: Microsoft.SqlServer.Dts.Runtime.TaskHost/Destination - : The final commit for the data insertion in "component "Destination" (94)" has started.
Error in: Microsoft.SqlServer.Dts.Runtime.TaskHost/File System Task : An error occurred with the following error message: "Could not find file 'filepathandname.csv'.".
我看到的一切都让我相信它基于权限并且运行包的用户无权访问该文件。通过调试运行时,它在我登录计算机时运行,但是当通过 IIS 运行时,它是运行它的 DefaultAppPool。
我添加的检查“lblErrorOutput.Text = WindowsIdentity.GetCurrent().Name;” 正在向我展示我期望的用户。我不太明白发生了什么。包执行是否忽略了模拟用户?如果是这样,我该如何服用。
谢谢