码迷,mamicode.com
首页 > 其他好文 > 详细

执行SSIS Package的两种方式

时间:2015-06-03 17:32:41      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:

1,使用SQL Server job

创建一个job用于执行package,可以制定一个schedule来定时执行job,也可以使用TSql 代码来执行job

EXEC msdb.dbo.sp_start_job NJOBNAME

msdb.dbo.sp_start_job 启动job,但是不等job运行完成,该stored procedure就立即返回,返回的结果标记job是否启动成功,可以通过msdb.dbo.sp_help_job 查看job的运行情况,示例代码如下

exec msdb.dbo.sp_help_job @job_name =Njobname,@job_aspect = JOB

2,C#调用package

添加引用 Microsoft.SqlServer.DTSRuntimeWrap.dll

引入命名空间:using DtsRun = Microsoft.SqlServer.Dts.Runtime.Wrapper;

示例代码如下:

            string strDtsxPath = @"D:\test.dtsx";

            DtsRun.Application dtsApp = new DtsRun.Application();
            DtsRun.IDTSPackage100 package = dtsApp.LoadPackage(strDtsxPath, true, null);
            
            DtsRun.DTSExecResult result = package.Execute();

            //获取包的错误信息
            //string message = string.Empty;
            //if (result.Equals(DtsRun.DTSExecResult.DTSER_FAILURE))
            //{
            //    for (int i = 0; i < package.Errors.Count; i++)
            //    {
            //        message += package.Errors[i].Description;
            //    }
            //}


如果报错,message 变量的信息是:“The Execute method on the task returned error code 0x80131621 (Mixed mode assembly is built against version ‘v2.0.50727‘ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.). The Execute method must succeed, and indicate the result using an "out" parameter.”

解决方案是配置App.config的节点: <startup useLegacyV2RuntimeActivationPolicy="true">

    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>

 

执行SSIS Package的两种方式

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/4548840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!