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);
}

No comments:

Post a Comment