运行 .net core 3.0 上的集成服务 SSIS
Running Integration services SSIS on .net core 3.0
我们正在将一个 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 核心或标准的绑定。我们尝试使用 Microsoft.SqlServer.SqlManagementObjects,它确实具有 standard2.0 绑定,但并没有真正翻译 1-1(类 不存在)并且似乎没有关于如何实现的在线信息运行来自 .net 的 SSIS core/standard。有人设法做到了吗?
您可以使用不同的方法从 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.As一起安装示例:
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 Server0\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();
更多信息,您可以参考以下链接:
我们正在将一个 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 核心或标准的绑定。我们尝试使用 Microsoft.SqlServer.SqlManagementObjects,它确实具有 standard2.0 绑定,但并没有真正翻译 1-1(类 不存在)并且似乎没有关于如何实现的在线信息运行来自 .net 的 SSIS core/standard。有人设法做到了吗?
您可以使用不同的方法从 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.As一起安装示例:
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 Server0\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();
更多信息,您可以参考以下链接: