我正在尝试从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;”向我展示了我期望的用户。我无法弄清楚发生了什么。包执行是否忽略了模拟用户?如果是这样,我该怎么做呢。
由于