在MVC中执行sis软件包

时间:2019-02-13 14:38:43

标签: asp.net-core ssis .net-core asp.net-core-mvc

下午

是否可以使用MVC执行SSIS程序包?我要创建的是一个Web应用程序,单击SSIS程序包后,它将有一个按钮。

SSIS项目已经设置并部署在MSSQL服务器上。

4 个答案:

答案 0 :(得分:4)

SQL Server 2012+提供了一种出色的机制,用于通过Integration Services目录SSISDB管理软件包及其执行。

以下代码提供了一个示例,该示例从位于Demo文件夹下的MyProjectName SSIS项目中运行程序包(Package2.dtsx),IntensityLevel程序包参数设置为11。

DECLARE @execution_id bigint;

EXEC SSISDB.catalog.create_execution
    @package_name = N'Package2.dtsx'
,   @execution_id = @execution_id OUTPUT
,   @folder_name = N'Demo'
,   @project_name = N'MyProjectName'
,   @use32bitruntime = False
,   @reference_id = NULL;

DECLARE @var0 int = 11;

EXEC SSISDB.catalog.set_execution_parameter_value
    @execution_id
,   @object_type = 30
,   @parameter_name = N'IntensityLevel'
,   @parameter_value = @var0;

DECLARE @var1 smallint = 1;

EXEC SSISDB.catalog.set_execution_parameter_value
    @execution_id
,   @object_type = 50
,   @parameter_name = N'LOGGING_LEVEL'
,   @parameter_value = @var1;

EXEC SSISDB.catalog.start_execution
    @execution_id;

获取有关如何构建上述SQL的示例的简单方法是打开SQL Server Management Studio(SSMS)并配置SSIS包的运行。导航到Integration Services目录,然后找到要运行的软件包。右键单击并选择执行...

Execute Package

将打开“配置”菜单,找到您要指定的参数。提供样本值,但不要单击确定。而是单击该脚本按钮,然后将脚本指定到新窗口(或剪贴板)

Configure Execution

现在,您拥有SSMS发出的确切命令以运行程序包。取得该代码,使用您选择的参数化方法,使MVC程序在参数的正确运行时值中存根,然后将所有TSQL打包到一个简单的数据库调用中(ole,ado,odbc都没有关系)< / p>

答案 1 :(得分:1)

您可以只创建一个存储过程,可以使用MSQL应用程序通过SQLClient进行调用。 然后,在此存储过程中,您可以启动SSIS包。(有关如何执行此操作的详细说明,请参见下面的链接)

https://www.mssqltips.com/sqlservertip/2992/how-to-execute-an-integration-services-ssis-package-from-a-sql-server-stored-procedure/

答案 2 :(得分:0)

C#可以用来执行部署到SSISDB的程序包,如下所示。在SqlConnection对象中创建的初始连接将是程序包部署到的服务器。在下面的示例中,ObjectType(为30)用于包参数。对于项目级别的参数,可以将其更改为20。

using System.Data.SqlClient;
using Microsoft.SqlServer.Management.IntegrationServices;
using System.Collections.ObjectModel;

        string folder = "Folder of Package";
        string project = "Project Of Package";
        string packageName = "PackageName.dtsx";
        string packageParameter = "ParameterValue";

        // server where package is deployed
        SqlConnection connString = new SqlConnection(@"Data Source=ServerWherePackageDeployed;Initial Catalog=SSISDB;Integrated Security=SSPI;");
        IntegrationServices ssisConnString = new IntegrationServices(connString);

        //create PackageInfo object for package to execute
        Microsoft.SqlServer.Management.IntegrationServices.PackageInfo package = ssisConnString.Catalogs["SSISDB"].Folders[folder].Projects[project].Packages[packageName];

        Collection <Microsoft.SqlServer.Management.IntegrationServices.PackageInfo.ExecutionValueParameterSet> parameterList = new Collection<Microsoft.SqlServer.Management.IntegrationServices.PackageInfo.ExecutionValueParameterSet>();

        //set logging level to basic
        parameterList.Add(new Microsoft.SqlServer.Management.IntegrationServices.PackageInfo.ExecutionValueParameterSet { ObjectType = 50, ParameterName = "LOGGING_LEVEL", ParameterValue = 1 });

        parameterList.Add(new Microsoft.SqlServer.Management.IntegrationServices.PackageInfo.ExecutionValueParameterSet { ObjectType = 30, ParameterName = "ParameterName", ParameterValue = packageParameter });

        package.Execute(false, null, parameterList);

答案 3 :(得分:0)

我创建了一个运行SSIS包的存储过程。在MVC中,它调用存储过程-

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Index()
{
    //code that updates DB

    #region Run Stored Procedure
    //connect to the SQL server
    var connection = new SqlConnection(_configuration.GetConnectionString("DatabaseConnection"));
    //command that runs procedure on the SQL server
    var command = new SqlCommand("RebuildSelection", connection)
    {
        CommandType = CommandType.StoredProcedure,
        CommandText = "RebuildSelection"
    };
    //get text from stored procedure to show success/error messages
    SqlParameter text = new SqlParameter("@Text", SqlDbType.NVarChar, 1000)
    {
        //output as its displayed to the user
        Direction = ParameterDirection.Output
    };
    //add the params
    command.Parameters.Add(text);
    connection.Open();
    //run query
    command.ExecuteNonQuery();
    //used to return success/error messages to user
    ViewData["Message"] = text.Value;
    connection.Close();
    #endregion

    return View();
}

link对创建过程有很大帮​​助。

one有助于向用户返回消息。