Monday, August 29, 2016

Fire Error event in case of Connection error

try
{
    SqlConnection conn = (Dts.Connections[adonConn].AcquireConnection(null) as SqlConnection);
    SqlCommand cmd = new SqlCommand(sql, conn);
    ....
}
catch (Exception ex)
{
    string text = string.Format("Failed to acquire connection to '{0}-[{1}]'. Error Message='{2}'"
        , adonConn
        , Dts.Connections[adonConn].ConnectionString
        , ex.Message).Replace(Environment.NewLine, "");
    Dts.Events.FireError(-1, "", text, "", 0);
}

Ho to fire Event from Script component

bool fireAgain = true;
IDTSComponentMetaData100 metaData;
metaData = this.ComponentMetaData;
metaData.FireError(-1, "", text, string.Empty, 0, ref fireAgain);