关闭

SQLSERVER的数据转换服务DTS的调用代码

538人阅读 评论(0) 收藏 举报


  /// <summary>
  /// url是包的全路径,packageName是包名;该方法抛出异常;执行的是DTS的结构化文件

  /// </summary>
  /// <param name="url">包的全路径</param>
  /// <param name="packageName">包名</param>
  /// <returns></returns>
  public static void   ExceDTSPackage(string url,string packageName)
  {
   DTS.Package2Class package = new DTS.Package2Class();
   try
   {
 
    Object MIA=System.Reflection.Missing.Value;
    package.LoadFromStorageFile(url,"","","",packageName,ref MIA);
    package.Execute();
    
   }

   catch(Exception e)
   {
    throw new Exception("执行“"+url+"”失败:"+e.Message);
   }
   finally
   {
    package.UnInitialize();
   }


  }

  /// <summary>
  /// DTS需要传入全局变量的,当然如果你原来设计的包没有全局变量,也不会影响到包执行的正确性.
  /// </summary>
  /// <param name="url"></param>
  /// <param name="packageName"></param>
  /// <param name="gdjdm"></param>
  /// <param name="bdzdm"></param>
  public static void   ExceDTSPackage(string url,string packageName,String bdzid_scmis,String bdzid_ztpj)
  {
   DTS.Package2Class package = new DTS.Package2Class();
   try
   {
 
    Object MIA=System.Reflection.Missing.Value;
    package.LoadFromStorageFile(url,"","","",packageName,ref MIA);
    package.GlobalVariables.Item("bdzid_scmis").let_Value(bdzid_scmis);
    package.GlobalVariables.Item("bdzid_ztpj").let_Value(bdzid_ztpj);
    package.SaveToStorageFile(url,"","",ref MIA,false);
    package.Execute();
    
   }

   catch(Exception e)
   {
    throw new Exception("执行“"+url+"”失败:"+e.Message);
   }
   finally
   {
    package.UnInitialize();
   }


  }

  /// <summary>
  /// 执行SQLSERVER上的DTS包
  /// </summary>
  /// <param name="ip"></param>
  /// <param name="userid"></param>
  /// <param name="pswd"></param>
  /// <param name="packagename"></param>
  public static void  ExceDTSSqlServer(string ip,string userid,string pswd,string packagename)
  {
   DTS.Package2Class package = new DTS.Package2Class();
   try
   {
 
    Object MIA = null;
    package.LoadFromSQLServer(ip,userid,pswd,DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default,"","","",packagename,ref MIA);
    package.Execute();
    
    
   }
   catch(Exception e)

   {
    throw new Exception("执行服务器“"+ip+"”上的包“"+packagename+"”时失败:"+e.Message);
   }
   finally
   {
    package.UnInitialize();
   }

  
  }

  /// <summary>
  /// DTS需要传入全局变量的
  /// </summary>
  /// <param name="ip"></param>
  /// <param name="userid"></param>
  /// <param name="pswd"></param>
  /// <param name="packagename"></param>
  /// <param name="gdjdm"></param>
  /// <param name="bdzdm"></param>
  public static void  ExceDTSSqlServer(string ip,string userid,string pswd,string packagename,string bdzid_scmis,string bdzid_ztpj)
  {
   DTS.Package2Class package = new DTS.Package2Class();
   try
   {
 
    Object MIA = null;
    package.LoadFromSQLServer(ip,userid,pswd,DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default,"","","",packagename,ref MIA);
    package.GlobalVariables.Item("bdzid_scmis").let_Value(bdzid_scmis);
    package.GlobalVariables.Item("bdzid_ztpj").let_Value(bdzid_ztpj);
    package.SaveToSQLServer(ip,userid,pswd,DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default,"","","",ref MIA,false);
    package.Execute();
    
    
   }
   catch(Exception e)

   {
    throw new Exception("执行服务器“"+ip+"”上的包“"+packagename+"”时失败:"+e.Message);
   }
   finally
   {
    package.UnInitialize();
   }

  
  }
 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2295次
    • 积分:46
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档