c# - 在 C# 中运行 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”不存在或您没有足够的权限。
我是否正确添加了参数?我不知道我可以看它是否正在设置,或者我是否有许可。
解决方案
我是否正确添加了参数?
您已经声明了一个名为 @SessionID 的变量而不是参数。
如果您需要传递一个变量值,那么您可以参考以下链接:
有关这两个对象(变量和参数)的更多信息,您可以参考以下文章:
推荐阅读
- c# - 错误:合并两个分支后在运行时出现“无法加载文件或程序集 Newtonsoft.Json”。两个分支都运行良好
- typescript - 使用带逗号的十进制将 Typescript 数字输入发送到后端
- postgresql - 将 Scala Slick 与数据库枚举一起使用
- swift - Beautiful Soup Find 等效于 Swift 的函数
- xml - 将 XML 转换为表时是否有正确的结果
- node.js - 猫鼬多字段选择不起作用
- google-apps-script - 谷歌通讯录脚本慢
- javascript - React - 如何在 html5 中捕获全屏视频请求?
- ruby-on-rails - 当 2 列是同一个表的外键时,Rails 3 列之间的唯一性
- javascript - 未捕获的 ReferenceError:尝试将总和分配给值时分配中的左侧无效