2

我正在尝试使用http://msdn.microsoft.com/en-us/library/ms345167.aspx中描述的方法在 SSIS 包中创建 ODBC 目标源我似乎无法初始化 ODBC 连接正确。这是我用来创建 ODBC 连接的代码

    // Specify the connection manager.
    component1.RuntimeConnectionCollection.NewAt(0);
    if (component1.RuntimeConnectionCollection.Count > 0)
    {
        component1.RuntimeConnectionCollection[0].ConnectionManager =
          DtsConvert.GetExtendedInterface(myPackage.Connections["ODBC Connection"]);
        component1.RuntimeConnectionCollection[0].ConnectionManagerID =
          myPackage.Connections["ODBC Vertica Connection"].ID;
        component1.RuntimeConnectionCollection[0].Name = myPackage.Connections["ODBC Connection"].Name;
    }

当我尝试使用此代码连接到服务器时,会引发 COM 异常。有没有人有使用 SSIS 生成创建的工作 ODBC 连接的示例

我使用代码从 component1 创建一个实例

CManagedComponentWrapper instance = component1.Instantiate(); 

当我尝试使用连接初始化对象的元数据时,会引发 COM 异常。抛出异常的行读取

instance.AcquireConnections(null); 

COM 异常本身是

对 COM 组件的调用已返回错误 HRESULT E_FAIL

转换为 System.Runtime.InteropServices.COMException 错误代码 -2147467259

这是完整的代码。我尝试将 ODBC 目标添加到现有数据流组件

    private IDTSComponentMetaData100 addODBCDest(MainPipe dataFlow_pipe, String tableName)
    {
        // ADO Net Data Source
        IDTSComponentMetaData100 component1 = dataFlow_pipe.ComponentMetaDataCollection.New();
        component1.Name = tableName + " ODBC Destination";
        Application app = new Application();

        component1.ComponentClassID = "{074B8736-CD73-40A5-822E-888215AF57DA}";
        // Get the design time instance of the component.
        CManagedComponentWrapper instance = component1.Instantiate();

        // Initialize the component
        try
        {
            instance.ProvideComponentProperties();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }

        // Specify the connection manager.
        component1.RuntimeConnectionCollection.NewAt(0);
        if (component1.RuntimeConnectionCollection.Count > 0)
        {
            component1.RuntimeConnectionCollection[0].ConnectionManager =
              DtsConvert.GetExtendedInterface(myPackage.Connections["ODBC Connection"]);
            component1.RuntimeConnectionCollection[0].ConnectionManagerID =
              myPackage.Connections["ODBC Vertica Connection"].ID;
            component1.RuntimeConnectionCollection[0].Name = myPackage.Connections["ODBC Connection"].Name;
        }

        // Set the custom properties.
        instance.SetComponentProperty("InsertMethod", 1);
        instance.SetComponentProperty("BatchSize", 10000);

        // Reinitialize the metadata.
        instance.AcquireConnections(null);  // crashes with COM exception -2147467259
        instance.ReinitializeMetaData();
        instance.ReleaseConnections();
        return component1;
    }
4

0 回答 0