public static DataException CreateDataException(this IDataCommand dataCommand, Exception inner)
        {
            var cmd = dataCommand.Command;

            // Failed to generate a command. Throw original exception.
            if (string.IsNullOrEmpty(cmd.CommandText))
            {
                ExceptionDispatchInfo.Capture(inner).Throw();
            }

            var exceptionToAnalyze = inner;

            if (exceptionToAnalyze is AggregateException)
            {
                exceptionToAnalyze = inner.InnerException;
            }

            var pos      = exceptionToAnalyze.Message.IndexOfAny(new[] { '\r', '\n' });
            var innerMsg = pos == -1 ? exceptionToAnalyze.Message : exceptionToAnalyze.Message.Substring(0, pos);

            var str = innerMsg + dataCommand.GetCommandString();

            return(new DataException(str, inner));
        }