Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#&;ASP.NET MVC 5-从按钮单击执行存储过程,无返回值_C#_Entity Framework_Stored Procedures_Ssis_Asp.net Mvc 5 - Fatal编程技术网

C#&;ASP.NET MVC 5-从按钮单击执行存储过程,无返回值

C#&;ASP.NET MVC 5-从按钮单击执行存储过程,无返回值,c#,entity-framework,stored-procedures,ssis,asp.net-mvc-5,C#,Entity Framework,Stored Procedures,Ssis,Asp.net Mvc 5,我正在尝试(我需要)创建一个小型web应用程序来管理一些ETL流程,为我的用户提供查看SQL Server数据和运行SSI包的几个按钮 我能够使用C#ASP.NET MVC CRUD教程处理网站创建(非常有用),并显示我需要的数据 然后,我创建了一个指向我的表和存储过程的数据模型,现在我“只”需要创建一个带有文本框的基本页面,以便为需要运行的每个存储过程插入一个参数和一个按钮 每个存储过程将运行一个SSIS包,目前不需要返回任何值 编辑:我能够收集更多的信息并像这样修改代码 控制器 using

我正在尝试(我需要)创建一个小型web应用程序来管理一些ETL流程,为我的用户提供查看SQL Server数据和运行SSI包的几个按钮

我能够使用C#ASP.NET MVC CRUD教程处理网站创建(非常有用),并显示我需要的数据

然后,我创建了一个指向我的表和存储过程的数据模型,现在我“只”需要创建一个带有文本框的基本页面,以便为需要运行的每个存储过程插入一个参数和一个按钮

每个存储过程将运行一个SSIS包,目前不需要返回任何值

编辑:我能够收集更多的信息并像这样修改代码

控制器

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Italist_Admin.Models;
using System.Data.SqlClient;
using System.Data.Entity.Core.Objects;

namespace Project.Controllers
{
    public class ToolsController : Controller
    {
        private ProjectEntities db = new ProjectEntities();

        public ActionResult Index()
        {
            ProjectEntities entities = new ProjectEntities();
            //return View(entities.SPU_RUNSSIS(""));
            return View();

        }
        [HttpPost]

        public ActionResult ExecExportOnly(string txtPeriod)  // to get the Student Details  
        {
            ProjectEntities entities = new ProjectEntities();

            entities.SPU_RUNSSIS(parameter);
            return View();

        }}}
查看

@{
    ViewBag.Title = "Tools";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Export Only</title>
</head>
<body>
    <div>
        @using (Html.BeginForm("ExecExportOnly", "Tools", FormMethod.Post))
        {
            <span>Period:</span> @Html.TextBox("txtPeriod")
            <input type="submit" value="Run Export" />
        }
    </div>
</body>
</html>
我在模型中添加了一个超时,因为在执行时,30秒后由于超时而失败

运行这段代码后,包在大约30秒后失败(SqlException:包失败。有关更多信息,请查看SSIS目录日志),在SQL跟踪中看到的30秒结束时,出现以下消息

RPC:Completed-exec[dbo].[SPU_RUNSSIS]@parameter='parametervalue'

如果我手动运行上面的代码,它就会工作

我就快到了,但似乎找不到在某个点触发存储过程执行的正确方法


提前感谢您的建议

我通过直接从c#代码启动SSI,而不是执行随后触发SSI执行的存储过程,成功地避免了这个问题

也许不是最好的解决方案,但似乎有效:

public ActionResult Index()
    {
        project entities = new project();
        return View();

    }
    public ActionResult ExecExportOnly(string txtPeriod)
    {
        project entities = new project();

        string targetServerName = ConfigurationManager.AppSettings["targetServerName"];
        string folderName = ConfigurationManager.AppSettings["folderName"];
        string projectName = ConfigurationManager.AppSettings["projectName"]; 
        string SSIS_ExportOnly = ConfigurationManager.AppSettings["SSIS_ExportOnly"];

        // Create a connection to the server
        string sqlConnectionString = ConfigurationManager.ConnectionStrings["Variable1"].ConnectionString;

        SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);

        // Create the Integration Services object
        IntegrationServices integrationServices = new IntegrationServices(sqlConnection);

        // Get the Integration Services catalog
        Catalog catalog = integrationServices.Catalogs["SSISDB"];

        // Get the folder
        CatalogFolder folder = catalog.Folders[folderName];

        // Get the project
        ProjectInfo project = folder.Projects[projectName];

        // Get the package
        PackageInfo package = project.Packages[SSIS_ExportOnly];

        //Set Parameters
        // Add a parameter collection for 'system' parameters (ObjectType = 50), package parameters (ObjectType = 30) and project parameters (ObjectType = 20)
        Collection<PackageInfo.ExecutionValueParameterSet> executionParameter = new Collection<PackageInfo.ExecutionValueParameterSet>();

        // Add execution parameter (value) to override the default asynchronized execution. If you leave this out the package is executed asynchronized
        //executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 50, ParameterName = "SYNCHRONIZED", ParameterValue = 1 });

        // Add execution parameter (value) to override the default logging level (0=None, 1=Basic, 2=Performance, 3=Verbose)
        executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 50, ParameterName = "LOGGING_LEVEL", ParameterValue = 3 });

        // Add a project parameter (value) to fill a project parameter
        //executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 20, ParameterName = "MyProjectParameter", ParameterValue = "some value" });

        // Add a project package (value) to fill a package parameter
        executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 30, ParameterName = "ParamPeriod", ParameterValue = txtPeriod });

        // Get the identifier of the execution to get the log
        //long executionIdentifier = package.Execute(false, null, executionParameter);

        // Run the package
        package.Execute(true, null,executionParameter);

        return View("Index");
    }
public ActionResult Index()
{
项目实体=新项目();
返回视图();
}
public ActionResult ExecExportOnly(字符串txtPeriod)
{
项目实体=新项目();
字符串targetServerName=ConfigurationManager.AppSettings[“targetServerName”];
字符串folderName=ConfigurationManager.AppSettings[“folderName”];
字符串projectName=ConfigurationManager.AppSettings[“projectName”];
字符串SSIS_ExportOnly=ConfigurationManager.AppSettings[“SSIS_ExportOnly”];
//创建到服务器的连接
字符串sqlConnectionString=ConfigurationManager.ConnectionString[“Variable1”]。ConnectionString;
SqlConnection SqlConnection=新的SqlConnection(sqlConnectionString);
//创建集成服务对象
IntegrationServices IntegrationServices=新的IntegrationServices(sqlConnection);
//获取集成服务目录
Catalog Catalog=integrationServices.Catalogs[“SSISDB”];
//获取文件夹
CatalogFolder=catalog.Folders[folderName];
//获得项目
ProjectInfo project=folder.Projects[projectName];
//拿到包裹
PackageInfo package=project.Packages[SSIS_ExportOnly];
//设置参数
//为“系统”参数(ObjectType=50)、包参数(ObjectType=30)和项目参数(ObjectType=20)添加参数集合
Collection executionParameter=新集合();
//添加执行参数(值)以覆盖默认的异步执行。如果不使用此参数,则包将异步执行
//添加(新的PackageInfo.ExecutionValueParameterSet{ObjectType=50,ParameterName=“SYNCHRONIZED”,ParameterValue=1});
//添加执行参数(值)以覆盖默认日志记录级别(0=无,1=基本,2=性能,3=详细)
添加(新的PackageInfo.ExecutionValueParameterSet{ObjectType=50,ParameterName=“LOGGING_LEVEL”,ParameterValue=3});
//添加项目参数(值)以填充项目参数
//添加(新的PackageInfo.ExecutionValueParameterSet{ObjectType=20,ParameterName=“MyProjectParameter”,ParameterValue=“some value”});
//添加项目包(值)以填充包参数
添加(新的PackageInfo.ExecutionValueParameterSet{ObjectType=30,ParameterName=“ParamPeriod”,ParameterValue=txtPeriod});
//获取执行的标识符以获取日志
//long executionIdentifier=package.Execute(false,null,executionParameter);
//运行包
package.Execute(true,null,executionParameter);
返回视图(“索引”);
}
无论如何谢谢你!
R

似乎包确实根据错误消息执行:SqlException:包失败。有关详细信息,请查看SSIS目录日志。ssis目录报告中有哪些用于执行的内容?没有,事实上ssis包没有运行。如果我手动执行相同的SQL代码,它将正确启动。我很难跟上你。你说运行代码包失败了,但是在你的评论中你说它没有运行。从哪里来的错误消息说包失败了?好吧,这确实很奇怪。该消息是从vs调试器返回的,但SSI甚至没有启动。也许可以检查连接详细信息,确保它正在您期望它运行的服务器上运行。在我发现了这么多测试之后,我陷入了客户端-SQL server-文件服务器之间的双跳问题(在这里我使用SSI导出文件). 我使用本教程暂时绕过了这个问题()在销毁所有内容之前,我需要深化Kerberos部分!
public ActionResult Index()
    {
        project entities = new project();
        return View();

    }
    public ActionResult ExecExportOnly(string txtPeriod)
    {
        project entities = new project();

        string targetServerName = ConfigurationManager.AppSettings["targetServerName"];
        string folderName = ConfigurationManager.AppSettings["folderName"];
        string projectName = ConfigurationManager.AppSettings["projectName"]; 
        string SSIS_ExportOnly = ConfigurationManager.AppSettings["SSIS_ExportOnly"];

        // Create a connection to the server
        string sqlConnectionString = ConfigurationManager.ConnectionStrings["Variable1"].ConnectionString;

        SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);

        // Create the Integration Services object
        IntegrationServices integrationServices = new IntegrationServices(sqlConnection);

        // Get the Integration Services catalog
        Catalog catalog = integrationServices.Catalogs["SSISDB"];

        // Get the folder
        CatalogFolder folder = catalog.Folders[folderName];

        // Get the project
        ProjectInfo project = folder.Projects[projectName];

        // Get the package
        PackageInfo package = project.Packages[SSIS_ExportOnly];

        //Set Parameters
        // Add a parameter collection for 'system' parameters (ObjectType = 50), package parameters (ObjectType = 30) and project parameters (ObjectType = 20)
        Collection<PackageInfo.ExecutionValueParameterSet> executionParameter = new Collection<PackageInfo.ExecutionValueParameterSet>();

        // Add execution parameter (value) to override the default asynchronized execution. If you leave this out the package is executed asynchronized
        //executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 50, ParameterName = "SYNCHRONIZED", ParameterValue = 1 });

        // Add execution parameter (value) to override the default logging level (0=None, 1=Basic, 2=Performance, 3=Verbose)
        executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 50, ParameterName = "LOGGING_LEVEL", ParameterValue = 3 });

        // Add a project parameter (value) to fill a project parameter
        //executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 20, ParameterName = "MyProjectParameter", ParameterValue = "some value" });

        // Add a project package (value) to fill a package parameter
        executionParameter.Add(new PackageInfo.ExecutionValueParameterSet { ObjectType = 30, ParameterName = "ParamPeriod", ParameterValue = txtPeriod });

        // Get the identifier of the execution to get the log
        //long executionIdentifier = package.Execute(false, null, executionParameter);

        // Run the package
        package.Execute(true, null,executionParameter);

        return View("Index");
    }