我们正在将一个 WPF 应用程序移植到 .net 核心,但我们有点卡在了 SSIS 部分。以前我们使用 Microsoft.SqlServer.Management.Sdk.Sfc
和 Microsoft.SqlServer.Smo
使用此代码运行 SSIS:
public void SSISUpload()
{
string targetServerName = "server";
string folderName = "Project1Folder";
string projectName = "Integration Services Project";
string packageName = "SSISPackage/Package.dtsx";
// Create a connection to the server
string sqlConnectionString = "Data Source=" + targetServerName +
";Initial Catalog=master;Integrated Security=SSPI;";
SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);
IntegrationServices integrationServices = new IntegrationServices(sqlConnection);
Catalog catalog = integrationServices.Catalogs["SSISDB"];
CatalogFolder folder = catalog.Folders[folderName];
ProjectInfo project = folder.Projects[projectName];
PackageInfo package = project.Packages[packageName];
// Run the package
package.Execute(false, null);
}
但是,上述引用与 .NET Framework 相关,似乎没有与 .net 核心或标准的绑定(bind)。我们尝试使用 Microsoft.SqlServer.SqlManagementObjects ,它确实具有 standard2.0 绑定(bind),但并没有真正翻译 1-1(类不存在)并且似乎没有任何关于如何从 .net 核心/标准运行 SSIS 的在线信息。有人设法做到这一点吗?
最佳答案
您可以使用不同的方法从 C# .net 核心执行 SSIS 包:
使用 Transact-SQL 命令
您可以简单地使用 SQLCommand
来执行 SSIS 包,而不是使用 Microsoft.SqlServer.SqlManagementObjects
,例如:
Declare @execution_id bigint
EXEC [SSISDB].[catalog].[create_execution] @package_name=N'Package.dtsx',
@execution_id=@execution_id OUTPUT,
@folder_name=N'Deployed Projects',
@project_name=N'Integration Services Project1',
@use32bitruntime=False,
@reference_id=Null
EXEC [SSISDB].[catalog].[start_execution] @execution_id
GO
您可以引用以下链接了解更多信息:
- Run an SSIS package from Visual Studio Code with Transact-SQL
- Deploy an SSIS project from Visual Studio Code with Transact-SQL
使用 DTEXEC 实用程序
另一种选择是使用 Process.Start执行 DTEXEC
应用程序的方法,该应用程序与 SQL Server 一起安装。例如:
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @"C:\Program Files\Microsoft SQL Server\130\DTS\Binn\DTExec.exe";
p.StartInfo.Arguments = "/ISServer \"\SSISDB\Project1Folder\Integration Services Project1\Package.dtsx\" /Server \"localhost\"";
p.Start();
Debug.WriteLine(p.StandardOutput.ReadToEnd());
p.WaitForExit();
更多信息,您可以引用以下链接:
关于c# - 在 .net core 3.0 上运行集成服务 SSIS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56559649/