Example #1
0
        private string[] ScanDtsObjectVariablesForErrors(DtsContainer o)
        {
            List <string> listOtherErrors = new List <string>();

            foreach (Variable v in o.Variables)
            {
                if (!v.SystemVariable && v.GetPackagePath().StartsWith(((IDTSPackagePath)o).GetPackagePath() + ".Variables[")) //only variables in this scope
                {
                    object val;
                    try
                    {
                        val = v.Value; //look at each value to see if each variable expression works
                    }
                    catch (Exception ex)
                    {
                        listOtherErrors.Add(ex.Message);
                        continue;
                    }

                    //if we haven't already gotten an error, try to validate the expression
                    IDTSInfoEventsWrapper events = new IDTSInfoEventsWrapper();
                    try
                    {
                        if (!string.IsNullOrEmpty(v.Expression))
                        {
                            Microsoft.SqlServer.Dts.Runtime.Wrapper.ExpressionEvaluatorClass eval = new Microsoft.SqlServer.Dts.Runtime.Wrapper.ExpressionEvaluatorClass();
                            eval.Expression = v.Expression;
                            eval.Events     = events;
#if KATMAI || DENALI || SQL2014
                            eval.Evaluate(DtsConvert.GetExtendedInterface(o.VariableDispenser), out val, false);
#else
                            eval.Evaluate(DtsConvert.ToVariableDispenser90(o.VariableDispenser), out val, false);
#endif
                        }
                    }
                    catch
                    {
                        if (events.Errors.Length > 0)
                        {
                            listOtherErrors.Add("Error in expression for variable " + v.QualifiedName + ": " + events.Errors[0]);
                        }
                        continue;
                    }
                }
            }
            return(listOtherErrors.ToArray());
        }
        private string[] ScanDtsObjectVariablesForErrors(DtsContainer o)
        {
            List<string> listOtherErrors = new List<string>();
            foreach (Variable v in o.Variables)
            {
                if (!v.SystemVariable && v.GetPackagePath().StartsWith(((IDTSPackagePath)o).GetPackagePath() + ".Variables[")) //only variables in this scope
                {
                    object val;
                    try
                    {
                        val = v.Value; //look at each value to see if each variable expression works
                    }
                    catch (Exception ex)
                    {
                        listOtherErrors.Add(ex.Message);
                        continue;
                    }

                    //if we haven't already gotten an error, try to validate the expression
                    IDTSInfoEventsWrapper events = new IDTSInfoEventsWrapper();
                    try
                    {
                        if (!string.IsNullOrEmpty(v.Expression))
                        {
                            Microsoft.SqlServer.Dts.Runtime.Wrapper.ExpressionEvaluatorClass eval = new Microsoft.SqlServer.Dts.Runtime.Wrapper.ExpressionEvaluatorClass();
                            eval.Expression = v.Expression;
                            eval.Events = events;
            #if KATMAI || DENALI
                            eval.Evaluate(DtsConvert.GetExtendedInterface(o.VariableDispenser), out val, false);
            #else
                            eval.Evaluate(DtsConvert.ToVariableDispenser90(o.VariableDispenser), out val, false);
            #endif
                        }
                    }
                    catch
                    {
                        if (events.Errors.Length > 0)
                            listOtherErrors.Add("Error in expression for variable " + v.QualifiedName + ": " + events.Errors[0]);
                        continue;
                    }
                }
            }
            return listOtherErrors.ToArray();
        }