예제 #1
0
        private IDataReader ExecuteReader(IJobContext jobContext, DataSourceErrorInspector errorInspector, string commandText)
        {
            IDataReader dataReader = null;

            try
            {
                jobContext?.AddCommand(m_commandWrappedForCancel);
                m_executionMetrics.StartTimer(DataProcessingMetrics.MetricType.ExecuteReader);
                try
                {
                    dataReader = m_command.ExecuteReader(CommandBehavior.SingleResult);
                }
                catch (Exception ex)
                {
                    if (m_odpContext.ContextMode == OnDemandProcessingContext.Mode.Streaming)
                    {
                        ErrorCode errorCode = ErrorCode.rsSuccess;
                        bool      flag      = errorInspector?.TryInterpretProviderErrorCode(ex, out errorCode) ?? false;
                        TraceExecuteReaderFailed(ex, commandText, flag ? new ErrorCode?(errorCode) : null);
                        if (flag)
                        {
                            string text = string.Format(CultureInfo.CurrentCulture, RPRes.Keys.GetString(ErrorCode.rsErrorExecutingCommand.ToString()), m_dataSet.Name.MarkAsPrivate());
                            throw new ReportProcessingQueryException(errorCode, ex, text);
                        }
                        if (errorInspector != null && errorInspector.IsOnPremiseServiceException(ex))
                        {
                            throw new ReportProcessingQueryOnPremiseServiceException(ErrorCode.rsErrorExecutingCommand, ex, m_dataSet.Name.MarkAsPrivate());
                        }
                    }
                    throw new ReportProcessingException(ErrorCode.rsErrorExecutingCommand, ex, m_dataSet.Name.MarkAsPrivate());
                }
                finally
                {
                    m_executionMetrics.RecordTimerMeasurement(DataProcessingMetrics.MetricType.ExecuteReader);
                }
            }
            finally
            {
                jobContext?.RemoveCommand(m_commandWrappedForCancel);
            }
            if (dataReader == null)
            {
                if (Global.Tracer.TraceError)
                {
                    Global.Tracer.Trace(TraceLevel.Error, "The source data reader is null. Cannot read results.");
                }
                throw new ReportProcessingException(ErrorCode.rsErrorCreatingDataReader, m_dataSet.Name.MarkAsPrivate());
            }
            return(dataReader);
        }
예제 #2
0
        private IDataReader ExecuteReader(IJobContext jobContext, DataSourceErrorInspector errorInspector, string commandText)
        {
            IDataReader dataReader = null;

            try
            {
                if (jobContext != null)
                {
                    jobContext.AddCommand(this.m_commandWrappedForCancel);
                }
                this.m_executionMetrics.StartTimer(DataProcessingMetrics.MetricType.ExecuteReader);
                try
                {
                    dataReader = this.m_command.ExecuteReader(CommandBehavior.SingleResult);
                    if (dataReader == null)
                    {
                        string connStr = this.m_dataSourceConnection.ConnectionString;
                        if (string.IsNullOrEmpty(connStr))
                        {
                            connStr = this.m_dataSourceConnection.ConnectionString = this.m_dataSource.ConnectStringExpression.OriginalText;
                        }
                        using (SqlConnection conn = new SqlConnection(connStr))
                        {
                            conn.Open();
                            using (var comm = conn.CreateCommand())
                            {
                                comm.CommandText = this.m_command.CommandText;
                                comm.CommandType = (System.Data.CommandType) this.m_command.CommandType;
                                foreach (IDataParameter p in this.m_command.Parameters)
                                {
                                    var p1 = comm.CreateParameter();
                                    p1.ParameterName = p.ParameterName;
                                    p1.Value         = p.Value;
                                    comm.Parameters.Add(p1);
                                }
                                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(comm);
                                var            table          = new System.Data.DataTable();
                                sqlDataAdapter.Fill(table);
                                dataReader = new Reporting.DataTableReader(table);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (this.m_odpContext.ContextMode == OnDemandProcessingContext.Mode.Streaming)
                    {
                        ErrorCode errorCode = ErrorCode.rsSuccess;
                        bool      flag      = errorInspector != null && errorInspector.TryInterpretProviderErrorCode(ex, out errorCode);
                        this.TraceExecuteReaderFailed(ex, commandText, flag ? new ErrorCode?(errorCode) : null);
                        if (flag)
                        {
                            string text = string.Format(CultureInfo.CurrentCulture, RPRes.Keys.GetString(ErrorCode.rsErrorExecutingCommand.ToString()), this.m_dataSet.Name.MarkAsPrivate());
                            throw new ReportProcessingQueryException(errorCode, ex, text);
                        }
                        if (errorInspector != null && errorInspector.IsOnPremiseServiceException(ex))
                        {
                            throw new ReportProcessingQueryOnPremiseServiceException(ErrorCode.rsErrorExecutingCommand, ex, this.m_dataSet.Name.MarkAsPrivate());
                        }
                    }
                    throw new ReportProcessingException(ErrorCode.rsErrorExecutingCommand, ex, this.m_dataSet.Name.MarkAsPrivate());
                }
                finally
                {
                    this.m_executionMetrics.RecordTimerMeasurement(DataProcessingMetrics.MetricType.ExecuteReader);
                }
            }
            finally
            {
                if (jobContext != null)
                {
                    jobContext.RemoveCommand(this.m_commandWrappedForCancel);
                }
            }
            if (dataReader == null)
            {
                if (Global.Tracer.TraceError)
                {
                    Global.Tracer.Trace(TraceLevel.Error, "The source data reader is null. Cannot read results.");
                }
                throw new ReportProcessingException(ErrorCode.rsErrorCreatingDataReader, this.m_dataSet.Name.MarkAsPrivate());
            }
            return(dataReader);
        }