【发布时间】:2019-10-12 03:11:00
【问题描述】:
我有一个如下所示的 SSIS 包:
它在命令行中通过 Visual Studio 或 DTEXEC 运行良好。我已经部署了它,如下所示:
当我在 WinForm 中通过 C# 连接并运行它时,它似乎只运行“截断表”任务。我回来说它是成功的,但它只运行了包的一部分,我不称之为成功。
这是我用来连接和运行的代码:
// Create a connection to the server
string sqlConnectionString = "Data Source=BSQL_01;Initial Catalog=master;Integrated Security=SSPI;";
SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);
MessageBox.Show("Created Connection");
// Create the Integration Services object
IntegrationServices integrationServices = new IntegrationServices(sqlConnection);
// Get the Integration Services catalog
Catalog catalog = integrationServices.Catalogs["SSISDB"];
MessageBox.Show("Created Catalog");
// Get the folder
CatalogFolder folder = catalog.Folders["PORGImport"];
MessageBox.Show("Created Folder");
// Get the project
ProjectInfo project = folder.Projects["PORGImport"];
MessageBox.Show("Created Project");
// Get the package
PackageInfo package = project.Packages["PORGImport.dtsx"];
MessageBox.Show("Created Package");
// Run the package
long executionIdentifier = package.Execute(false, null);
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");
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");
}
我查看了 SQL Server 上的包,我看到了这个错误:
购买文件循环:警告:For Each File 枚举器为空。 For Each File 枚举器未找到任何与 文件模式,或者指定的目录为空。
这对我来说没有意义,因为它都是从我的 PC 上运行的,我可以访问该目录,它通过命令行和 Visual Studio 运行良好。
环境
- MS SQL Server 2014 (v12.0.5546.0)
- MS Visual Studio 15(v14 更新 3)
【问题讨论】:
-
您可能具有访问权限,但这并不意味着运行 SQL Server 的帐户可以访问。另外,您是说您连接的 SQL Server 正在运行您的 PC?
-
我已经在你的另一个问题中问过你:SQL Server 是否与 VS / 命令行在同一台机器上运行?
-
不,SQL Server 在另一台机器上。我正在使用 UNC 路径作为文件夹位置。
-
运行 SQL Server 的帐户是否可以访问本地 PC 上的硬盘?你还没有回答这个问题。在我看来,它不应该,因此它为什么不起作用。这些文件应该在文件服务器共享上,或者在服务帐户有权访问的 SQL Server 本地上,而不是在您的 PC 上。
标签: c# sql-server ssis ssis-2014