动态保存SSIS包的输出

时间:2011-06-15 17:05:21

标签: c# sql-server-2005 sql-server-2008 ssis

使用SSIS包,我生成ExcelSheet作为输出。我通过C#源代码调用SSIS包。目前我实际上将文件保存为:pkgTR.Variables [“dPath”]。值= @“c:\”+ sFileName;

我们希望将功能另存为最终用户 - 谁决定将文件保存在C:\或D:\或他想要保存文件的位置。

try
{
    string pkgTRPath = @"C:\Reports\SSISPackages\GenerateTransactionReport.dtsx";
    Package pkgTR;
    Microsoft.SqlServer.Dts.Runtime.Application app;
    DTSExecResult pkgResults;

    app = new Microsoft.SqlServer.Dts.Runtime.Application();
    pkgTR = app.LoadPackage(pkgTRPath, null);

    pkgTR.Variables["sConn"].Value = System.Configuration.ConfigurationManager.AppSettings["SSISConn"];
    pkgTR.Variables["sDate"].Value = txtFromDate.Text;
    pkgTR.Variables["eDate"].Value = txtToDate.Text;
    pkgTR.Variables["sSortCode"].Value = drpSortCode.SelectedValue.TrimEnd();
    string sFileName = "TransactionReport_" + drpSortCode.SelectedValue.TrimEnd() + ".xls";
    pkgTR.Variables["dPath"].Value = @"c:\" + sFileName;

    pkgResults = pkgTR.Execute();
    var reportID = drpSortCode.SelectedValue.TrimEnd();

    if (pkgTR.ExecutionResult.ToString() == "Success")
    {
        Response.Write(String.Format(@"<script language=javascript>alert('Excel Report for {0} is Generated');</script>", reportID));
    }
    else if (pkgTR.ExecutionResult.ToString() == "Failure")
    {
        Response.Write("<script language=javascript>alert('Failure:Unable to generate report!!');</script>");
    }
}

catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

1 个答案:

答案 0 :(得分:1)

如果从C#调用软件包,在启动软件包之前不能弹出C#中的对话框,然后在执行时将目录路径传递给SSIS包吗?