我正在尝试使用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异常本身就是
错误HRESULT E_FAIL已从调用COM组件返回
哪个转换为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;
}