无法通过IntegrationServices连接到服务器

时间:2019-05-25 08:09:08

标签: c# sql-server winforms ssis

我正在尝试连接到SQL Server以运行SSIS包。我承认这是我第一次尝试这种方法,因此我不确定自己是否正确。

我在行上收到“无法连接到服务器BSQL_01失败”的一般错误:

IntegrationServices ssisServer = new IntegrationServices(ssisConnection);

这是我的SQL Server,唯一的软件包是我要运行的软件包:

enter image description here

这是我遇到问题的代码。

// Connection to the database server where the packages are located
SqlConnection ssisConnection = new SqlConnection("Data Source=BSQL_01;Initial Catalog=master;Integrated Security=SSPI;");

// SSIS server object with connection
IntegrationServices ssisServer = new IntegrationServices(ssisConnection);

// The reference to the package which you want to execute
PackageInfo ssisPackage = ssisServer.Catalogs["SSISDB"].Folders["PORGImport"].Projects["PORGImport"].Packages["PORGImport.dtsx"];

long executionIdentifier = ssisPackage.Execute(false, null, executionParameter);

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

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

if (executionOperation.Status == Operation.ServerOperationStatus.Success) {
    Console.WriteLine("Success");
    MessageBox.Show("Success");

} else if (executionOperation.Status == Operation.ServerOperationStatus.Failed) {
    Console.WriteLine("Failed");
    MessageBox.Show("Failed");

} else {
    Console.WriteLine("Something Went Really Wrong");
    MessageBox.Show("Oh Crap");
}

更新

好吧,我将ConnectionString中的初始目录更改为“ Mmaster”,并且不再收到错误。当我获得“成功”时,它似乎可以运行,但是,当我检查应该填充的表时,什么都没有。

1 个答案:

答案 0 :(得分:0)

ConnectionString的“初始目录”必须是“主”,而不是“ SSISDB”

SqlConnection ssisConnection = new SqlConnection("Data Source=BSQL_01;Initial Catalog=master;Integrated Security=SSPI;");