Looking up SSIS HResult / COMException ErrorCode

Published Mar 25 2019 02:26 PM 214 Views
Not applicable
First published on MSDN on Aug 04, 2009

The method I describe in my post about handling COMExceptions during package generation works if you have control over the package generation code, but sometimes you’ll be using third party libraries, or debugging after the fact.

Note, the error codes, symbolic names, and descriptions for all of the SSIS HResults can all be found on the Integration Services Error and Message Reference page in Books Online. This should be your first stop if you want to quickly (and manually) lookup an SSIS error code.

However, if you want to do this programmatically…

The symbolic name for each SSIS error is slightly more useful than the hex error code value, and will sometimes be enough for you to isolate your problem right away. You can programmatically determine the symbolic name by comparing the error code value against the members of the HResults class.

public static string GetSymbolicName(int errorCode)
{
string symbolicName = string.Empty;
HResults hresults = new HResults();

foreach (FieldInfo fieldInfo in hresults.GetType().GetFields())
{
if ((int)fieldInfo.GetValue(hresults) == errorCode)
{
symbolicName = fieldInfo.Name;
break;
}
}

return symbolicName;
}


I could use this function in a try/catch block to give the user additional information as to why the error occurred.



catch (COMException ex)
{
string symbolicName = GetSymbolicName(ex.ErrorCode);
Console.WriteLine("Symbolic Name: {0}", symbolicName);
}


Retrieving the actual error message for a given SSIS HResult is a little more involved. We can use the FormatMessage API to pull the message directly out of the dtsmsg100.dll (in 2005, it’s dtsmsg.dll). To do this, we’ll need to expose a couple of native methods so we can pinvoke them.



static class NativeMethods
{
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);

[DllImport("kernel32.dll")]
public static extern bool FreeLibrary(IntPtr hModule);

[DllImport("Kernel32.dll", SetLastError = true)]
public static extern uint FormatMessage(uint dwFlags, IntPtr lpSource,
uint dwMessageId, uint dwLanguageId, ref IntPtr lpBuffer,
uint nSize, IntPtr pArguments);

public const int FORMAT_MESSAGE_ALLOCATE_BUFFER = 256;
public const int FORMAT_MESSAGE_IGNORE_INSERTS = 512;
public const int FORMAT_MESSAGE_FROM_STRING = 1024;
public const int FORMAT_MESSAGE_FROM_HMODULE = 2048;
public const int FORMAT_MESSAGE_FROM_SYSTEM = 4096;
public const int FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192;
public const int FORMAT_MESSAGE_MAX_WIDTH_MASK = 255;
}


First we’ll get a handle to dtsmsg100.dll using LoadLibrary :



IntPtr handle = NativeMethods.LoadLibrary("dtsmsg100.dll");
if (handle == IntPtr.Zero)
{
throw new Exception("Couldn't open library dtsmsg100.dll");
}


Then we’ll call FormatMessage . The first parameter is a set of flags – we’ll want the native method to do the allocation, the messages to be loaded from a specific DLL (dtsmsg), and we don’t want to do any parameter substitution.



const int FormatMessageFlags = NativeMethods.FORMAT_MESSAGE_ALLOCATE_BUFFER | // FormatMessage will allocate buffer
NativeMethods.FORMAT_MESSAGE_FROM_HMODULE | // Messages are loaded from specified DLL
NativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS; // Don't perform place holder substitutions


IntPtr lpMsgBuf = IntPtr.Zero;
uint dwChars = NativeMethods.FormatMessage(
FormatMessageFlags,
handle, // handle to error message dll
errorCode, // error code we're looking up
0, // 0 for default language
ref lpMsgBuf, // message buffer
2048, // max size of message buffer
IntPtr.Zero); // substitution arguments

if (dwChars == 0)
{
// FormatMessage will set LastError
throw new Win32Exception();
}

string sMessage = Marshal.PtrToStringAnsi(lpMsgBuf);

// Free the buffer
Marshal.FreeHGlobal(lpMsgBuf);

Once we have the error message, we can release the handle to dtsmsg using FreeLibrary .



Using the same scenario from my previous post , getting a COMException off a call to AcquireConnection() gives me an HResult of 0xC020801C. Programmatically retrieving the error message gives me this:




SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.  The AcquireConnection method call to the connection manager " %1 " failed with error code 0x %2!8.8X! .  There may be error messages posted before this with more information on why the AcquireConnection method call failed.




Notice the format placeholders (%1 and %2!8.8X!) weren’t filled in. This is because we used the FORMAT_MESSAGE_IGNORE_INSERTS flag on FormatMessage – we wouldn’t have known what values to put in there, since we weren’t the ones that raised the original exception.



I’ve encapsulated all of this logic in the HResultsHelper class. I’ve included the full code listing (including a CreatePackage method from previous API posts) here.



-------





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;

namespace ErrorMsgFromHResult
{
public class HResultHelper : IDisposable
{
const string MessageDLL = @"dtsmsg100.dll";

private IntPtr handle = IntPtr.Zero;
bool disposed;
const int FormatMessageFlags = NativeMethods.FORMAT_MESSAGE_ALLOCATE_BUFFER | // FormatMessage will allocate buffer
NativeMethods.FORMAT_MESSAGE_FROM_HMODULE | // Messages are loaded from specified DLL
NativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS; // Don't perform place holder substitutions

public HResultHelper()
{
// Load the DLL we'll get the error messages from
handle = NativeMethods.LoadLibrary(MessageDLL);
if (handle == IntPtr.Zero)
{
throw new Exception(string.Format(CultureInfo.CurrentCulture, "Couldn't open library: {0}", MessageDLL));
}
}

public string GetErrorMessage(COMException comException)
{
return GetErrorMessage((uint)comException.ErrorCode);
}

public string GetErrorMessage(uint errorCode)
{
IntPtr lpMsgBuf = IntPtr.Zero;
uint dwChars = NativeMethods.FormatMessage(
FormatMessageFlags,
handle, // handle to error message dll
errorCode, // error code we're looking up
0, // 0 for default language
ref lpMsgBuf, // message buffer
2048, // max size of message buffer
IntPtr.Zero); // substitution arguments

if (dwChars == 0)
{
// FormatMessage will set LastError
throw new Win32Exception();
}

string sRet = Marshal.PtrToStringAnsi(lpMsgBuf);

// Free the buffer
Marshal.FreeHGlobal(lpMsgBuf);

return sRet;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if(!this.disposed)
{
NativeMethods.FreeLibrary(handle);
handle = IntPtr.Zero;
disposed = true;
}
}

~HResultHelper()
{
Dispose(false);
}

static class NativeMethods
{
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);

[DllImport("kernel32.dll")]
public static extern bool FreeLibrary(IntPtr hModule);

[DllImport("Kernel32.dll", SetLastError = true)]
public static extern uint FormatMessage(uint dwFlags, IntPtr lpSource,
uint dwMessageId, uint dwLanguageId, ref IntPtr lpBuffer,
uint nSize, IntPtr pArguments);

public const int FORMAT_MESSAGE_ALLOCATE_BUFFER = 256;
public const int FORMAT_MESSAGE_IGNORE_INSERTS = 512;
public const int FORMAT_MESSAGE_FROM_STRING = 1024;
public const int FORMAT_MESSAGE_FROM_HMODULE = 2048;
public const int FORMAT_MESSAGE_FROM_SYSTEM = 4096;
public const int FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192;
public const int FORMAT_MESSAGE_MAX_WIDTH_MASK = 255;
}
}


class Program
{
static void Main(string[] args)
{
HResultHelper helper = new HResultHelper();

try
{
CreatePackage();
}
catch (COMException ex)
{
string errorMessage = helper.GetErrorMessage(ex);
Console.WriteLine(errorMessage);
}

helper.Dispose();
}

static Package CreatePackage()
{
Package package = new Package();

// Add Data Flow Task
Executable dataFlowTask = package.Executables.Add("STOCK:PipelineTask");

// Set the name (otherwise it will be a random GUID value)
TaskHost taskHost = dataFlowTask as TaskHost;
taskHost.Name = "Data Flow Task";

// We need a reference to the InnerObject to add items to the data flow
MainPipe pipeline = taskHost.InnerObject as MainPipe;

// Set the IDTSComponentEvent handler to capture the details from any
// COMExceptions raised during package generation
ComponentEventHandler events = new ComponentEventHandler();
pipeline.Events = DtsConvert.GetExtendedInterface(events as IDTSComponentEvents);

//
// Add connection manager
//

ConnectionManager connection = package.Connections.Add("OLEDB");
connection.Name = "localhost";
connection.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorksDW2008;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;Connect Timeout=1";

//
// Add OLEDB Source
//

IDTSComponentMetaData100 srcComponent = pipeline.ComponentMetaDataCollection.New();
srcComponent.ComponentClassID = "DTSAdapter.OleDbSource";
srcComponent.ValidateExternalMetadata = true;
IDTSDesigntimeComponent100 srcDesignTimeComponent = srcComponent.Instantiate();
srcDesignTimeComponent.ProvideComponentProperties();
srcComponent.Name = "OleDb Source";

// Configure it to read from the given table
srcDesignTimeComponent.SetComponentProperty("AccessMode", 0);
srcDesignTimeComponent.SetComponentProperty("OpenRowset", "[DimCustomer]");

// Set the connection manager
srcComponent.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(connection);
srcComponent.RuntimeConnectionCollection[0].ConnectionManagerID = connection.ID;

// Retrieve the column metadata
srcDesignTimeComponent.AcquireConnections(null);
srcDesignTimeComponent.ReinitializeMetaData();
srcDesignTimeComponent.ReleaseConnections();

//
// Add OLEDB Destination
//

IDTSComponentMetaData100 destComponent = pipeline.ComponentMetaDataCollection.New();
destComponent.ComponentClassID = "DTSAdapter.OleDbDestination";
destComponent.ValidateExternalMetadata = true;

IDTSDesigntimeComponent100 destDesignTimeComponent = destComponent.Instantiate();
destDesignTimeComponent.ProvideComponentProperties();
destComponent.Name = "OleDb Destination";

destDesignTimeComponent.SetComponentProperty("AccessMode", 3);
destDesignTimeComponent.SetComponentProperty("OpenRowset", "[DimCustomer_Copy]");

// set connection
destComponent.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(connection);
destComponent.RuntimeConnectionCollection[0].ConnectionManagerID = connection.ID;

// get metadata
destDesignTimeComponent.AcquireConnections(null);
destDesignTimeComponent.ReinitializeMetaData();
destDesignTimeComponent.ReleaseConnections();

//
// Connect source and destination
//

IDTSPath100 path = pipeline.PathCollection.New();
path.AttachPathAndPropagateNotifications(srcComponent.OutputCollection[0], destComponent.InputCollection[0]);

//
// Configure the destination
//

IDTSInput100 destInput = destComponent.InputCollection[0];
IDTSVirtualInput100 destVirInput = destInput.GetVirtualInput();
IDTSInputColumnCollection100 destInputCols = destInput.InputColumnCollection;
IDTSExternalMetadataColumnCollection100 destExtCols = destInput.ExternalMetadataColumnCollection;
IDTSOutputColumnCollection100 sourceColumns = srcComponent.OutputCollection[0].OutputColumnCollection;

// The OLEDB destination requires you to hook up the external columns
foreach (IDTSOutputColumn100 outputCol in sourceColumns)
{
// Get the external column id
IDTSExternalMetadataColumn100 extCol = (IDTSExternalMetadataColumn100)destExtCols[outputCol.Name];
if (extCol != null)
{
// Create an input column from an output col of previous component.
destVirInput.SetUsageType(outputCol.ID, DTSUsageType.UT_READONLY);
IDTSInputColumn100 inputCol = destInputCols.GetInputColumnByLineageID(outputCol.ID);
if (inputCol != null)
{
// map the input column with an external metadata column
destDesignTimeComponent.MapInputColumn(destInput.ID, inputCol.ID, extCol.ID);
}
}
}

return package;
}

class ComponentEventHandler : IDTSComponentEvents
{
private void HandleEvent(string type, string subComponent, string description)
{
Console.WriteLine("[{0}] {1}: {2}", type, subComponent, description);
}

#region IDTSComponentEvents Members

public void FireBreakpointHit(BreakpointTarget breakpointTarget)
{
}

public void FireCustomEvent(string eventName, string eventText, ref object[] arguments, string subComponent, ref bool fireAgain)
{
}

public bool FireError(int errorCode, string subComponent, string description, string helpFile, int helpContext)
{
HandleEvent("Error", subComponent, description);
return true;
}

public void FireInformation(int informationCode, string subComponent, string description, string helpFile, int helpContext, ref bool fireAgain)
{
HandleEvent("Information", subComponent, description);
}

public void FireProgress(string progressDescription, int percentComplete, int progressCountLow, int progressCountHigh, string subComponent, ref bool fireAgain)
{
}

public bool FireQueryCancel()
{
return true;
}

public void FireWarning(int warningCode, string subComponent, string description, string helpFile, int helpContext)
{
HandleEvent("Warning", subComponent, description);
}

#endregion
}
}
}
%3CLINGO-SUB%20id%3D%22lingo-sub-387586%22%20slang%3D%22en-US%22%3ELooking%20up%20SSIS%20HResult%20%2F%20COMException%20ErrorCode%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-387586%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Aug%2004%2C%202009%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EThe%20method%20I%20describe%20in%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fmattm%2Farchive%2F2009%2F08%2F03%2Fdebugging-a-comexception-during-package-generation.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20my%20post%20about%20handling%20COMExceptions%20during%20package%20generation%20%3C%2FA%3E%20works%20if%20you%20have%20control%20over%20the%20package%20generation%20code%2C%20but%20sometimes%20you%E2%80%99ll%20be%20using%20third%20party%20libraries%2C%20or%20debugging%20after%20the%20fact.%3C%2FP%3E%0A%20%20%3CP%3ENote%2C%20the%20error%20codes%2C%20symbolic%20names%2C%20and%20descriptions%20for%20all%20of%20the%20SSIS%20HResults%20can%20all%20be%20found%20on%20the%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms345164.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Integration%20Services%20Error%20and%20Message%20Reference%20%3C%2FA%3E%20page%20in%20Books%20Online.%20This%20should%20be%20your%20first%20stop%20if%20you%20want%20to%20quickly%20(and%20manually)%20lookup%20an%20SSIS%20error%20code.%3C%2FP%3E%0A%20%20%3CP%3EHowever%2C%20if%20you%20want%20to%20do%20this%20programmatically%E2%80%A6%3C%2FP%3E%0A%20%20%3CP%3EThe%20symbolic%20name%20for%20each%20SSIS%20error%20is%20slightly%20more%20useful%20than%20the%20hex%20error%20code%20value%2C%20and%20will%20sometimes%20be%20enough%20for%20you%20to%20isolate%20your%20problem%20right%20away.%20You%20can%20programmatically%20determine%20the%20symbolic%20name%20by%20comparing%20the%20error%20code%20value%20against%20the%20members%20of%20the%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmicrosoft.sqlserver.dts.runtime.hresults_members.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20HResults%20%3C%2FA%3E%20class.%3C%2FP%3Epublic%20static%20string%20GetSymbolicName(int%20errorCode)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20string%20symbolicName%20%3D%20string.Empty%3B%20%3CBR%20%2F%3E%20HResults%20hresults%20%3D%20new%20HResults()%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20foreach%20(FieldInfo%20fieldInfo%20in%20hresults.GetType().GetFields())%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20if%20((int)fieldInfo.GetValue(hresults)%20%3D%3D%20errorCode)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20symbolicName%20%3D%20fieldInfo.Name%3B%20%3CBR%20%2F%3E%20break%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20return%20symbolicName%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CA%20href%3D%22http%3A%2F%2F11011.net%2Fsoftware%2Fvspaste%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3EI%20could%20use%20this%20function%20in%20a%20try%2Fcatch%20block%20to%20give%20the%20user%20additional%20information%20as%20to%20why%20the%20error%20occurred.%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20catch%20(COMException%20ex)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20string%20symbolicName%20%3D%20GetSymbolicName(ex.ErrorCode)%3B%20%3CBR%20%2F%3E%20Console.WriteLine(%22Symbolic%20Name%3A%20%7B0%7D%22%2C%20symbolicName)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CA%20href%3D%22http%3A%2F%2F11011.net%2Fsoftware%2Fvspaste%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3ERetrieving%20the%20actual%20error%20message%20for%20a%20given%20SSIS%20HResult%20is%20a%20little%20more%20involved.%20We%20can%20use%20the%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms679351(VS.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20FormatMessage%20%3C%2FA%3E%20API%20to%20pull%20the%20message%20directly%20out%20of%20the%20dtsmsg100.dll%20(in%202005%2C%20it%E2%80%99s%20dtsmsg.dll).%20To%20do%20this%2C%20we%E2%80%99ll%20need%20to%20expose%20a%20couple%20of%20native%20methods%20so%20we%20can%20pinvoke%20them.%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20static%20class%20NativeMethods%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%5BDllImport(%22kernel32.dll%22)%5D%20%3CBR%20%2F%3E%20public%20static%20extern%20IntPtr%20LoadLibrary(string%20dllToLoad)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5BDllImport(%22kernel32.dll%22)%5D%20%3CBR%20%2F%3E%20public%20static%20extern%20bool%20FreeLibrary(IntPtr%20hModule)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5BDllImport(%22Kernel32.dll%22%2C%20SetLastError%20%3D%20true)%5D%20%3CBR%20%2F%3E%20public%20static%20extern%20uint%20FormatMessage(uint%20dwFlags%2C%20IntPtr%20lpSource%2C%20%3CBR%20%2F%3E%20uint%20dwMessageId%2C%20uint%20dwLanguageId%2C%20ref%20IntPtr%20lpBuffer%2C%20%3CBR%20%2F%3E%20uint%20nSize%2C%20IntPtr%20pArguments)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_ALLOCATE_BUFFER%20%3D%20256%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_IGNORE_INSERTS%20%3D%20512%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_FROM_STRING%20%3D%201024%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_FROM_HMODULE%20%3D%202048%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_FROM_SYSTEM%20%3D%204096%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_ARGUMENT_ARRAY%20%3D%208192%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_MAX_WIDTH_MASK%20%3D%20255%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CA%20href%3D%22http%3A%2F%2F11011.net%2Fsoftware%2Fvspaste%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3EFirst%20we%E2%80%99ll%20get%20a%20handle%20to%20dtsmsg100.dll%20using%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms684175(VS.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20LoadLibrary%20%3C%2FA%3E%20%3A%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20IntPtr%20handle%20%3D%20NativeMethods.LoadLibrary(%22dtsmsg100.dll%22)%3B%20%3CBR%20%2F%3E%20if%20(handle%20%3D%3D%20IntPtr.Zero)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20throw%20new%20Exception(%22Couldn't%20open%20library%20dtsmsg100.dll%22)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CA%20href%3D%22http%3A%2F%2F11011.net%2Fsoftware%2Fvspaste%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3EThen%20we%E2%80%99ll%20call%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms679351(VS.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20FormatMessage%20%3C%2FA%3E%20.%20The%20first%20parameter%20is%20a%20set%20of%20flags%20%E2%80%93%20we%E2%80%99ll%20want%20the%20native%20method%20to%20do%20the%20allocation%2C%20the%20messages%20to%20be%20loaded%20from%20a%20specific%20DLL%20(dtsmsg)%2C%20and%20we%20don%E2%80%99t%20want%20to%20do%20any%20parameter%20substitution.%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20const%20int%20FormatMessageFlags%20%3D%20NativeMethods.FORMAT_MESSAGE_ALLOCATE_BUFFER%20%7C%20%2F%2F%20FormatMessage%20will%20allocate%20buffer%20%3CBR%20%2F%3E%20NativeMethods.FORMAT_MESSAGE_FROM_HMODULE%20%7C%20%2F%2F%20Messages%20are%20loaded%20from%20specified%20DLL%20%3CBR%20%2F%3E%20NativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS%3B%20%2F%2F%20Don't%20perform%20place%20holder%20substitutions%20%3CBR%20%2F%3E%20%3CA%20href%3D%22http%3A%2F%2F11011.net%2Fsoftware%2Fvspaste%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20IntPtr%20lpMsgBuf%20%3D%20IntPtr.Zero%3B%20%3CBR%20%2F%3E%20uint%20dwChars%20%3D%20NativeMethods.FormatMessage(%20%3CBR%20%2F%3E%20FormatMessageFlags%2C%20%3CBR%20%2F%3E%20handle%2C%20%2F%2F%20handle%20to%20error%20message%20dll%20%3CBR%20%2F%3E%20errorCode%2C%20%2F%2F%20error%20code%20we're%20looking%20up%20%3CBR%20%2F%3E%200%2C%20%2F%2F%200%20for%20default%20language%20%3CBR%20%2F%3E%20ref%20lpMsgBuf%2C%20%2F%2F%20message%20buffer%20%3CBR%20%2F%3E%202048%2C%20%2F%2F%20max%20size%20of%20message%20buffer%20%3CBR%20%2F%3E%20IntPtr.Zero)%3B%20%2F%2F%20substitution%20arguments%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20if%20(dwChars%20%3D%3D%200)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%2F%2F%20FormatMessage%20will%20set%20LastError%20%3CBR%20%2F%3E%20throw%20new%20Win32Exception()%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20string%20sMessage%20%3D%20Marshal.PtrToStringAnsi(lpMsgBuf)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20Free%20the%20buffer%20%3CBR%20%2F%3E%20Marshal.FreeHGlobal(lpMsgBuf)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3EOnce%20we%20have%20the%20error%20message%2C%20we%20can%20release%20the%20handle%20to%20dtsmsg%20using%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms683152(VS.85).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20FreeLibrary%20%3C%2FA%3E%20.%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3EUsing%20the%20same%20scenario%20from%20my%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fmattm%2Farchive%2F2009%2F08%2F03%2Fdebugging-a-comexception-during-package-generation.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20previous%20post%20%3C%2FA%3E%20%2C%20getting%20a%20COMException%20off%20a%20call%20to%20AcquireConnection()%20gives%20me%20an%20HResult%20of%200xC020801C.%20Programmatically%20retrieving%20the%20error%20message%20gives%20me%20this%3A%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CBLOCKQUOTE%3E%3CBR%20%2F%3E%3CP%3ESSIS%20Error%20Code%20DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.%26nbsp%3B%20The%20AcquireConnection%20method%20call%20to%20the%20connection%20manager%20%22%20%3CSTRONG%3E%20%251%20%3C%2FSTRONG%3E%20%22%20failed%20with%20error%20code%200x%20%3CSTRONG%3E%20%252!8.8X!%20%3C%2FSTRONG%3E%20.%26nbsp%3B%20There%20may%20be%20error%20messages%20posted%20before%20this%20with%20more%20information%20on%20why%20the%20AcquireConnection%20method%20call%20failed.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FBLOCKQUOTE%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3ENotice%20the%20format%20placeholders%20(%251%20and%20%252!8.8X!)%20weren%E2%80%99t%20filled%20in.%20This%20is%20because%20we%20used%20the%20FORMAT_MESSAGE_IGNORE_INSERTS%20flag%20on%20FormatMessage%20%E2%80%93%20we%20wouldn%E2%80%99t%20have%20known%20what%20values%20to%20put%20in%20there%2C%20since%20we%20weren%E2%80%99t%20the%20ones%20that%20raised%20the%20original%20exception.%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3EI%E2%80%99ve%20encapsulated%20all%20of%20this%20logic%20in%20the%20HResultsHelper%20class.%20I%E2%80%99ve%20included%20the%20full%20code%20listing%20(including%20a%20CreatePackage%20method%20from%20previous%20API%20posts)%20here.%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3E-------%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20using%20System%3B%20%3CBR%20%2F%3E%20using%20System.Collections.Generic%3B%20%3CBR%20%2F%3E%20using%20System.Linq%3B%20%3CBR%20%2F%3E%20using%20System.Text%3B%20%3CBR%20%2F%3E%20using%20Microsoft.SqlServer.Dts.Runtime%3B%20%3CBR%20%2F%3E%20using%20Microsoft.SqlServer.Dts.Pipeline.Wrapper%3B%20%3CBR%20%2F%3E%20using%20System.Runtime.InteropServices%3B%20%3CBR%20%2F%3E%20using%20System.ComponentModel%3B%20%3CBR%20%2F%3E%20using%20System.Globalization%3B%20%3CBR%20%2F%3E%20using%20System.Reflection%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20namespace%20ErrorMsgFromHResult%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20public%20class%20HResultHelper%20%3A%20IDisposable%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20const%20string%20MessageDLL%20%3D%20%40%22dtsmsg100.dll%22%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20private%20IntPtr%20handle%20%3D%20IntPtr.Zero%3B%20%3CBR%20%2F%3E%20bool%20disposed%3B%20%3CBR%20%2F%3E%20const%20int%20FormatMessageFlags%20%3D%20NativeMethods.FORMAT_MESSAGE_ALLOCATE_BUFFER%20%7C%20%2F%2F%20FormatMessage%20will%20allocate%20buffer%20%3CBR%20%2F%3E%20NativeMethods.FORMAT_MESSAGE_FROM_HMODULE%20%7C%20%2F%2F%20Messages%20are%20loaded%20from%20specified%20DLL%20%3CBR%20%2F%3E%20NativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS%3B%20%2F%2F%20Don't%20perform%20place%20holder%20substitutions%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20HResultHelper()%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%2F%2F%20Load%20the%20DLL%20we'll%20get%20the%20error%20messages%20from%20%3CBR%20%2F%3E%20handle%20%3D%20NativeMethods.LoadLibrary(MessageDLL)%3B%20%3CBR%20%2F%3E%20if%20(handle%20%3D%3D%20IntPtr.Zero)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20throw%20new%20Exception(string.Format(CultureInfo.CurrentCulture%2C%20%22Couldn't%20open%20library%3A%20%7B0%7D%22%2C%20MessageDLL))%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20string%20GetErrorMessage(COMException%20comException)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20return%20GetErrorMessage((uint)comException.ErrorCode)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20string%20GetErrorMessage(uint%20errorCode)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20IntPtr%20lpMsgBuf%20%3D%20IntPtr.Zero%3B%20%3CBR%20%2F%3E%20uint%20dwChars%20%3D%20NativeMethods.FormatMessage(%20%3CBR%20%2F%3E%20FormatMessageFlags%2C%20%3CBR%20%2F%3E%20handle%2C%20%2F%2F%20handle%20to%20error%20message%20dll%20%3CBR%20%2F%3E%20errorCode%2C%20%2F%2F%20error%20code%20we're%20looking%20up%20%3CBR%20%2F%3E%200%2C%20%2F%2F%200%20for%20default%20language%20%3CBR%20%2F%3E%20ref%20lpMsgBuf%2C%20%2F%2F%20message%20buffer%20%3CBR%20%2F%3E%202048%2C%20%2F%2F%20max%20size%20of%20message%20buffer%20%3CBR%20%2F%3E%20IntPtr.Zero)%3B%20%2F%2F%20substitution%20arguments%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20if%20(dwChars%20%3D%3D%200)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%2F%2F%20FormatMessage%20will%20set%20LastError%20%3CBR%20%2F%3E%20throw%20new%20Win32Exception()%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20string%20sRet%20%3D%20Marshal.PtrToStringAnsi(lpMsgBuf)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20Free%20the%20buffer%20%3CBR%20%2F%3E%20Marshal.FreeHGlobal(lpMsgBuf)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20return%20sRet%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20void%20Dispose()%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20Dispose(true)%3B%20%3CBR%20%2F%3E%20GC.SuppressFinalize(this)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20private%20void%20Dispose(bool%20disposing)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20if(!this.disposed)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20NativeMethods.FreeLibrary(handle)%3B%20%3CBR%20%2F%3E%20handle%20%3D%20IntPtr.Zero%3B%20%3CBR%20%2F%3E%20disposed%20%3D%20true%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20~HResultHelper()%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20Dispose(false)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20static%20class%20NativeMethods%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%5BDllImport(%22kernel32.dll%22)%5D%20%3CBR%20%2F%3E%20public%20static%20extern%20IntPtr%20LoadLibrary(string%20dllToLoad)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5BDllImport(%22kernel32.dll%22)%5D%20%3CBR%20%2F%3E%20public%20static%20extern%20bool%20FreeLibrary(IntPtr%20hModule)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5BDllImport(%22Kernel32.dll%22%2C%20SetLastError%20%3D%20true)%5D%20%3CBR%20%2F%3E%20public%20static%20extern%20uint%20FormatMessage(uint%20dwFlags%2C%20IntPtr%20lpSource%2C%20%3CBR%20%2F%3E%20uint%20dwMessageId%2C%20uint%20dwLanguageId%2C%20ref%20IntPtr%20lpBuffer%2C%20%3CBR%20%2F%3E%20uint%20nSize%2C%20IntPtr%20pArguments)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_ALLOCATE_BUFFER%20%3D%20256%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_IGNORE_INSERTS%20%3D%20512%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_FROM_STRING%20%3D%201024%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_FROM_HMODULE%20%3D%202048%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_FROM_SYSTEM%20%3D%204096%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_ARGUMENT_ARRAY%20%3D%208192%3B%20%3CBR%20%2F%3E%20public%20const%20int%20FORMAT_MESSAGE_MAX_WIDTH_MASK%20%3D%20255%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20class%20Program%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20static%20void%20Main(string%5B%5D%20args)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20HResultHelper%20helper%20%3D%20new%20HResultHelper()%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20try%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20CreatePackage()%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20catch%20(COMException%20ex)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20string%20errorMessage%20%3D%20helper.GetErrorMessage(ex)%3B%20%3CBR%20%2F%3E%20Console.WriteLine(errorMessage)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20helper.Dispose()%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20static%20Package%20CreatePackage()%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20Package%20package%20%3D%20new%20Package()%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20Add%20Data%20Flow%20Task%20%3CBR%20%2F%3E%20Executable%20dataFlowTask%20%3D%20package.Executables.Add(%22STOCK%3APipelineTask%22)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20Set%20the%20name%20(otherwise%20it%20will%20be%20a%20random%20GUID%20value)%20%3CBR%20%2F%3E%20TaskHost%20taskHost%20%3D%20dataFlowTask%20as%20TaskHost%3B%20%3CBR%20%2F%3E%20taskHost.Name%20%3D%20%22Data%20Flow%20Task%22%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20We%20need%20a%20reference%20to%20the%20InnerObject%20to%20add%20items%20to%20the%20data%20flow%20%3CBR%20%2F%3E%20MainPipe%20pipeline%20%3D%20taskHost.InnerObject%20as%20MainPipe%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20Set%20the%20IDTSComponentEvent%20handler%20to%20capture%20the%20details%20from%20any%20%3CBR%20%2F%3E%20%2F%2F%20COMExceptions%20raised%20during%20package%20generation%20%3CBR%20%2F%3E%20ComponentEventHandler%20events%20%3D%20new%20ComponentEventHandler()%3B%20%3CBR%20%2F%3E%20pipeline.Events%20%3D%20DtsConvert.GetExtendedInterface(events%20as%20IDTSComponentEvents)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%2F%2F%20Add%20connection%20manager%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ConnectionManager%20connection%20%3D%20package.Connections.Add(%22OLEDB%22)%3B%20%3CBR%20%2F%3E%20connection.Name%20%3D%20%22localhost%22%3B%20%3CBR%20%2F%3E%20connection.ConnectionString%20%3D%20%22Data%20Source%3Dlocalhost%3BInitial%20Catalog%3DAdventureWorksDW2008%3BProvider%3DSQLNCLI10.1%3BIntegrated%20Security%3DSSPI%3BAuto%20Translate%3DFalse%3BConnect%20Timeout%3D1%22%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%2F%2F%20Add%20OLEDB%20Source%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20IDTSComponentMetaData100%20srcComponent%20%3D%20pipeline.ComponentMetaDataCollection.New()%3B%20%3CBR%20%2F%3E%20srcComponent.ComponentClassID%20%3D%20%22DTSAdapter.OleDbSource%22%3B%20%3CBR%20%2F%3E%20srcComponent.ValidateExternalMetadata%20%3D%20true%3B%20%3CBR%20%2F%3E%20IDTSDesigntimeComponent100%20srcDesignTimeComponent%20%3D%20srcComponent.Instantiate()%3B%20%3CBR%20%2F%3E%20srcDesignTimeComponent.ProvideComponentProperties()%3B%20%3CBR%20%2F%3E%20srcComponent.Name%20%3D%20%22OleDb%20Source%22%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20Configure%20it%20to%20read%20from%20the%20given%20table%20%3CBR%20%2F%3E%20srcDesignTimeComponent.SetComponentProperty(%22AccessMode%22%2C%200)%3B%20%3CBR%20%2F%3E%20srcDesignTimeComponent.SetComponentProperty(%22OpenRowset%22%2C%20%22%5BDimCustomer%5D%22)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20Set%20the%20connection%20manager%20%3CBR%20%2F%3E%20srcComponent.RuntimeConnectionCollection%5B0%5D.ConnectionManager%20%3D%20DtsConvert.GetExtendedInterface(connection)%3B%20%3CBR%20%2F%3E%20srcComponent.RuntimeConnectionCollection%5B0%5D.ConnectionManagerID%20%3D%20connection.ID%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20Retrieve%20the%20column%20metadata%20%3CBR%20%2F%3E%20srcDesignTimeComponent.AcquireConnections(null)%3B%20%3CBR%20%2F%3E%20srcDesignTimeComponent.ReinitializeMetaData()%3B%20%3CBR%20%2F%3E%20srcDesignTimeComponent.ReleaseConnections()%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%2F%2F%20Add%20OLEDB%20Destination%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20IDTSComponentMetaData100%20destComponent%20%3D%20pipeline.ComponentMetaDataCollection.New()%3B%20%3CBR%20%2F%3E%20destComponent.ComponentClassID%20%3D%20%22DTSAdapter.OleDbDestination%22%3B%20%3CBR%20%2F%3E%20destComponent.ValidateExternalMetadata%20%3D%20true%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20IDTSDesigntimeComponent100%20destDesignTimeComponent%20%3D%20destComponent.Instantiate()%3B%20%3CBR%20%2F%3E%20destDesignTimeComponent.ProvideComponentProperties()%3B%20%3CBR%20%2F%3E%20destComponent.Name%20%3D%20%22OleDb%20Destination%22%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20destDesignTimeComponent.SetComponentProperty(%22AccessMode%22%2C%203)%3B%20%3CBR%20%2F%3E%20destDesignTimeComponent.SetComponentProperty(%22OpenRowset%22%2C%20%22%5BDimCustomer_Copy%5D%22)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20set%20connection%20%3CBR%20%2F%3E%20destComponent.RuntimeConnectionCollection%5B0%5D.ConnectionManager%20%3D%20DtsConvert.GetExtendedInterface(connection)%3B%20%3CBR%20%2F%3E%20destComponent.RuntimeConnectionCollection%5B0%5D.ConnectionManagerID%20%3D%20connection.ID%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20get%20metadata%20%3CBR%20%2F%3E%20destDesignTimeComponent.AcquireConnections(null)%3B%20%3CBR%20%2F%3E%20destDesignTimeComponent.ReinitializeMetaData()%3B%20%3CBR%20%2F%3E%20destDesignTimeComponent.ReleaseConnections()%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%2F%2F%20Connect%20source%20and%20destination%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20IDTSPath100%20path%20%3D%20pipeline.PathCollection.New()%3B%20%3CBR%20%2F%3E%20path.AttachPathAndPropagateNotifications(srcComponent.OutputCollection%5B0%5D%2C%20destComponent.InputCollection%5B0%5D)%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%2F%2F%20Configure%20the%20destination%20%3CBR%20%2F%3E%20%2F%2F%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20IDTSInput100%20destInput%20%3D%20destComponent.InputCollection%5B0%5D%3B%20%3CBR%20%2F%3E%20IDTSVirtualInput100%20destVirInput%20%3D%20destInput.GetVirtualInput()%3B%20%3CBR%20%2F%3E%20IDTSInputColumnCollection100%20destInputCols%20%3D%20destInput.InputColumnCollection%3B%20%3CBR%20%2F%3E%20IDTSExternalMetadataColumnCollection100%20destExtCols%20%3D%20destInput.ExternalMetadataColumnCollection%3B%20%3CBR%20%2F%3E%20IDTSOutputColumnCollection100%20sourceColumns%20%3D%20srcComponent.OutputCollection%5B0%5D.OutputColumnCollection%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%2F%2F%20The%20OLEDB%20destination%20requires%20you%20to%20hook%20up%20the%20external%20columns%20%3CBR%20%2F%3E%20foreach%20(IDTSOutputColumn100%20outputCol%20in%20sourceColumns)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%2F%2F%20Get%20the%20external%20column%20id%20%3CBR%20%2F%3E%20IDTSExternalMetadataColumn100%20extCol%20%3D%20(IDTSExternalMetadataColumn100)destExtCols%5BoutputCol.Name%5D%3B%20%3CBR%20%2F%3E%20if%20(extCol%20!%3D%20null)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%2F%2F%20Create%20an%20input%20column%20from%20an%20output%20col%20of%20previous%20component.%20%3CBR%20%2F%3EdestVirInput.SetUsageType(outputCol.ID%2C%20DTSUsageType.UT_READONLY)%3B%20%3CBR%20%2F%3E%20IDTSInputColumn100%20inputCol%20%3D%20destInputCols.GetInputColumnByLineageID(outputCol.ID)%3B%20%3CBR%20%2F%3E%20if%20(inputCol%20!%3D%20null)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%2F%2F%20map%20the%20input%20column%20with%20an%20external%20metadata%20column%20%3CBR%20%2F%3E%20destDesignTimeComponent.MapInputColumn(destInput.ID%2C%20inputCol.ID%2C%20extCol.ID)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20return%20package%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20class%20ComponentEventHandler%20%3A%20IDTSComponentEvents%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20private%20void%20HandleEvent(string%20type%2C%20string%20subComponent%2C%20string%20description)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20Console.WriteLine(%22%5B%7B0%7D%5D%20%7B1%7D%3A%20%7B2%7D%22%2C%20type%2C%20subComponent%2C%20description)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23region%20IDTSComponentEvents%20Members%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20void%20FireBreakpointHit(BreakpointTarget%20breakpointTarget)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20void%20FireCustomEvent(string%20eventName%2C%20string%20eventText%2C%20ref%20object%5B%5D%20arguments%2C%20string%20subComponent%2C%20ref%20bool%20fireAgain)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20bool%20FireError(int%20errorCode%2C%20string%20subComponent%2C%20string%20description%2C%20string%20helpFile%2C%20int%20helpContext)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20HandleEvent(%22Error%22%2C%20subComponent%2C%20description)%3B%20%3CBR%20%2F%3E%20return%20true%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20void%20FireInformation(int%20informationCode%2C%20string%20subComponent%2C%20string%20description%2C%20string%20helpFile%2C%20int%20helpContext%2C%20ref%20bool%20fireAgain)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20HandleEvent(%22Information%22%2C%20subComponent%2C%20description)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20void%20FireProgress(string%20progressDescription%2C%20int%20percentComplete%2C%20int%20progressCountLow%2C%20int%20progressCountHigh%2C%20string%20subComponent%2C%20ref%20bool%20fireAgain)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20bool%20FireQueryCancel()%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20return%20true%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20public%20void%20FireWarning(int%20warningCode%2C%20string%20subComponent%2C%20string%20description%2C%20string%20helpFile%2C%20int%20helpContext)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20HandleEvent(%22Warning%22%2C%20subComponent%2C%20description)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23endregion%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CA%20href%3D%22http%3A%2F%2F11011.net%2Fsoftware%2Fvspaste%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-387586%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Aug%2004%2C%202009%20The%20method%20I%20describe%20in%20my%20post%20about%20handling%20COMExceptions%20during%20package%20generation%20works%20if%20you%20have%20control%20over%20the%20package%20generation%20code%2C%20but%20sometimes%20you%E2%80%99ll%20be%20using%20third%20party%20libraries%2C%20or%20debugging%20after%20the%20fact.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-387586%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 25 2019 02:26 PM
Updated by: