首页 > 解决方案 > 在 C# 中运行 SSIS 包时出现“参数不存在或您没有足够的权限”

问题描述

我有一个带有一堆变量的 SSIS 包,如下所示: 在此处输入图像描述

我正在尝试使用以下代码从 C# Windows 窗体应用程序调用 SSIS 包:

// Create a connection to the server
string sqlConnectionString = "Data Source=BSQL_01;Initial Catalog=master;Integrated Security=SSPI;";
SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);

// Create the Integration Services object
IntegrationServices integrationServices = new IntegrationServices(sqlConnection);

// Get the Integration Services catalog
Catalog catalog = integrationServices.Catalogs["SSISDB"];

// Get the folder
CatalogFolder folder = catalog.Folders["PORGPackages"];

// Get the project
ProjectInfo project = folder.Projects["PORGPackages"];

// Get the package
PackageInfo package = project.Packages["POHandler.dtsx"];

// Add project parameter
Collection<PackageInfo.ExecutionValueParameterSet> executionParameter = new Collection<PackageInfo.ExecutionValueParameterSet>();
executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 20, ParameterName = "SessionID", ParameterValue = "636943168325507712" });

// Run the package
long executionIdentifier = package.Execute(false, null, executionParameter);

ExecutionOperation executionOperation = integrationServices.Catalogs["SSISDB"].Executions[executionIdentifier];

while (!executionOperation.Completed) {
    System.Threading.Thread.Sleep(5000);
    executionOperation.Refresh();
    MessageBox.Show("Running...");
}

if (executionOperation.Status == Operation.ServerOperationStatus.Success) {
    Console.WriteLine("Success");
} else if (executionOperation.Status == Operation.ServerOperationStatus.Failed) {
    Console.WriteLine("Failed");
} else {
    Console.WriteLine("Something Went Really Wrong");
}

我收到以下错误:

参数“SessionID”不存在或您没有足够的权限。

我是否正确添加了参数?我不知道我可以看它是否正在设置,或者我是否有许可。

标签: c#sql-serverwinformsssisetl

解决方案


我是否正确添加了参数?

您已经声明了一个名为 @SessionID 的变量而不是参数。

如果您需要传递一个变量值,那么您可以参考以下链接:

有关这两个对象(变量和参数)的更多信息,您可以参考以下文章:


推荐阅读