SSIS以编程方式生成:项目连接管理器不会出现在项目连接列表中

时间:2016-10-05 07:41:49

标签: c# ssis

我从c#创建Package,这段代码用于处理SQL Server 2016,但现在使用Sql server 2014,它给了我一些问题: 我正在以这种方式将包添加到项目中:

        proj.PackageItems.Remove("HSTG_" + hstg_table.tablename + ".dtsx");
        proj.PackageItems.Add(p, "HSTG_" + hstg_table.tablename + ".dtsx");

在项目的连接列表中,我可以看到3个连接管理器, 但在包中我看到0连接然后当然当我尝试以这种方式访问​​其中一个p.Connections [" META"]它给我一个错误,说无法找到连接。 local_variable local_variable2

1 个答案:

答案 0 :(得分:0)

我没有读取现有的ispac,而是以编程方式创建一个ispac,它确实有效。但我仍然不明白为什么它不能以前一种方式运作。

 /* Previous way of doing it which work for me on a previous project but not 
working anymore
*/
Project proj = Project.OpenProject(fixed_settings.Default.PROJECT_ISPAC);

// New way by creating the project on the fly
            //Test creation project
            Project proj = Project.CreateProject();
            ConnectionManagerItem connectionManagerItem_meta =   proj.ConnectionManagerItems.Add("OLEDB", "META.conmgr");
            connectionManagerItem_meta.ConnectionManager.Name = "META";
            connectionManagerItem_meta.ConnectionManager.ConnectionString = "Data Source=" + fixed_settings.Default.server_meta + ";Initial Catalog=" + fixed_settings.Default.server_meta + ";Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;";

            ConnectionManagerItem connectionManagerItem_stg = proj.ConnectionManagerItems.Add("OLEDB", "STG.conmgr");
            connectionManagerItem_stg.ConnectionManager.Name = "STG";
            connectionManagerItem_stg.ConnectionManager.ConnectionString = "Data Source = " + fixed_settings.Default.server_stg + "; Initial Catalog = " + fixed_settings.Default.database_stg + "; Provider = SQLNCLI11.1; Integrated Security = SSPI; Auto Translate = False;";

            ConnectionManagerItem connectionManagerItem_hstg = proj.ConnectionManagerItems.Add("OLEDB", "HSTG.conmgr");
            connectionManagerItem_hstg.ConnectionManager.Name = "HSTG";
            connectionManagerItem_hstg.ConnectionManager.ConnectionString = "Data Source=" + fixed_settings.Default.server_hstg + ";Initial Catalog=" + fixed_settings.Default.database_hstg + ";Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;";