System.Data.Common.DbCommand.ExecuteReader(System.Data.CommandBehavior)

Here are the examples of the csharp api class System.Data.Common.DbCommand.ExecuteReader(System.Data.CommandBehavior) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

70 Examples 7

1. Example

View license
protected void InitializeReader(EntityConnection connection, IEnumerable<EntityStoreSchemaFilterEntry> filters)
        {
            _connection = connection;

            _command = EntityStoreSchemaGeneratorDatabaseSchemaLoader.CreateFilteredCommand(
                        _connection,
                        FunctionDetailSql,
                        FunctionOrderByClause,
                        EntityStoreSchemaFilterObjectTypes.Function,
                        new List<EntityStoreSchemaFilterEntry>(filters),
                        new string[] { FunctionDetailAlias });
            _reader = _command.ExecuteReader(CommandBehavior.SequentialAccess);
        }

2. Example

View license
public new DbDataReaderRedundant ExecuteReader(CommandBehavior behavior)
        {
            return (DbDataReaderRedundant)base.ExecuteReader(behavior);
        }

3. Example

Project: linq2db
Source File: RetryingDbCommand.cs
View license
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
		{
			return _policy.Execute(() => _command.ExecuteReader(behavior));
		}

4. Example

Project: Kalman.Studio
Source File: Database.cs
View license
IDataReader DoExecuteReader(DbCommand command, CommandBehavior cmdBehavior)
        {
            try
            {
                //DateTime startTime = DateTime.Now;
                IDataReader reader = command.ExecuteReader(cmdBehavior);
                //instrumentationProvider.FireCommandExecutedEvent(startTime);
                return reader;
            }
            catch (Exception)
            {
                //instrumentationProvider.FireCommandFailedEvent(command.CommandText, ConnectionStringNoCredentials, e);
                throw;
            }
        }

5. Example

Project: referencesource
Source File: DBCommand.cs
View license
protected virtual Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) {
            if (cancellationToken.IsCancellationRequested) {
                return ADP.CreatedTaskWithCancellation<DbDataReader>();
            }
            else {
                CancellationTokenRegistration registration = new CancellationTokenRegistration();
                if (cancellationToken.CanBeCanceled) {
                    registration = cancellationToken.Register(CancelIgnoreFailure);
                }

                try {
                    return Task.FromResult<DbDataReader>(ExecuteReader(behavior));
                }
                catch (Exception e) {
                    registration.Dispose();
                    return ADP.CreatedTaskWithException<DbDataReader>(e);
                }
            }
        }

6. Example

Project: mysql-connector-net
Source File: MySqlCommand.cs
View license
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
    {
      return ExecuteReader(behavior);
    }

7. Example

Project: nhibernate-core
Source File: InformixDialect.cs
View license
public override DbDataReader GetResultSet(DbCommand statement)
		{
			return statement.ExecuteReader(CommandBehavior.SingleResult);
		}

8. Example

Project: effort
Source File: DbCommandWrapper.cs
View license
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            return this.wrappedCommand.ExecuteReader(behavior);
        }

9. Example

Project: Glimpse
Source File: GlimpseDbCommand.cs
View license
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            DbDataReader reader;
            var commandId = Guid.NewGuid();

            var timer = this.LogCommandSeed();
            this.LogCommandStart(commandId, timer);
            try
            {
                reader = InnerCommand.ExecuteReader(behavior);
            }
            catch (Exception exception)
            {
                this.LogCommandError(commandId, timer, exception, "ExecuteDbDataReader");
                throw;
            }

            this.LogCommandEnd(commandId, timer, reader.RecordsAffected, "ExecuteDbDataReader");

            return new GlimpseDbDataReader(reader, InnerCommand, InnerConnection.ConnectionId, commandId);
        }

10. Example

Project: Dos.ORM
Source File: Database.cs
View license
private IDataReader DoExecuteReader(DbCommand command, CommandBehavior cmdBehavior)
        {

            WriteLog(command);

            return command.ExecuteReader(cmdBehavior);

        }

11. Example

Project: Dos.ORM
Source File: Database.cs
View license
private IDataReader DoExecuteReader(DbCommand command, CommandBehavior cmdBehavior)
        {

            WriteLog(command);

            return command.ExecuteReader(cmdBehavior);

        }

12. Example

Project: Dos.ORM
Source File: Database.cs
View license
private IDataReader DoExecuteReader(DbCommand command, CommandBehavior cmdBehavior)
        {

            WriteLog(command);

            return command.ExecuteReader(cmdBehavior);

        }

13. Example

Project: ALinq
Source File: Connection.cs
View license
private DbDataReader CreateNewReader(CommandBehavior behavior)
        {
            var command = this.Connection.CreateCommand();
            var reader = command.ExecuteReader(behavior);
            return reader;
        }

14. Example

View license
protected override DataTable GetSchemaTable (DbCommand srcCommand) {
            SqlCommand sqlCommand = srcCommand as SqlCommand;
            SqlNotificationRequest  notificationRequest     = sqlCommand.Notification;
            bool                    notificationAutoEnlist  = sqlCommand.NotificationAutoEnlist;

            sqlCommand.Notification             = null;
            sqlCommand.NotificationAutoEnlist   = false;

            try {
                using (SqlDataReader dataReader = sqlCommand.ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo)){
                    return dataReader.GetSchemaTable();
                }
            }
            finally {
                sqlCommand.Notification             = notificationRequest;
                sqlCommand.NotificationAutoEnlist   = notificationAutoEnlist;
            }

        }

15. Example

View license
private IEnumerable<DataRow> LoadDataTable(string sql, Func<IEnumerable<DataRow>, IEnumerable<DataRow>> orderByFunc, DataTable table, EntityStoreSchemaFilterObjectTypes queryTypes, IEnumerable<EntityStoreSchemaFilterEntry> filters, params string[] filterAliases)
        {
            using (EntityCommand command = CreateFilteredCommand(_connection, sql, null, queryTypes, new List<EntityStoreSchemaFilterEntry>(filters), filterAliases))
            {
                using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess))
                {
                    object[] values = new object[table.Columns.Count];
                    while (reader.Read())
                    {
                        reader.GetValues(values);
                        table.Rows.Add(values);
                    }

                    return orderByFunc(table.AsEnumerable());
                }
            }
        }

16. Example

Project: nanoprofiler
Source File: ProfiledDbCommand.cs
View license
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            var dbProfiler = _getDbProfiler();
            if (dbProfiler == null) return _dbCommand.ExecuteReader();

            DbDataReader reader = null;
            dbProfiler.ExecuteDbCommand(
                DbExecuteType.Reader
                , _command
                , () => reader = _dbCommand.ExecuteReader(behavior)
                , Tags);

            var profiledReader = reader as ProfiledDbDataReader;
            if (profiledReader != null)
            {
                return profiledReader;
            }

            return new ProfiledDbDataReader(reader, dbProfiler);
        }

17. Example

View license
public DbDataReader GetQueryAsDataReader(IQueryable query)
		{
			return SetupCommand(GetCommand(query), true).ExecuteReader(CommandBehavior.CloseConnection);
		}

18. Example

Project: LCLFramework
Source File: LIDbAccesser.cs
View license
public DbDataReader ExecuteReader(string sql, IList<DbParameter> parameters, CommandType commandType)
        {
            DbCommand command = CreateDbCommand(sql, parameters, commandType);
            command.Connection.Open();
            return command.ExecuteReader(CommandBehavior.CloseConnection);
        }

19. Example

Project: nuodb-dotnet
Source File: NuoDbCommand.cs
View license
public override object ExecuteScalar()
        {
            using (IDataReader reader = ExecuteReader(CommandBehavior.SingleRow))
            {
                if (!reader.Read() || reader.FieldCount < 1)
                    return null;
                return reader.GetValue(0);
            }
        }

20. Example

View license
public DbDataReader ExecuteReader(SqlQueryCommand command)
        {
            if (command == null) 
                throw new ArgumentNullException("command");

            using (var dbCommand = _dbConnection.CreateCommand())
            {
                dbCommand.Connection = _dbConnection;
                dbCommand.CommandTimeout = _commandTimeout;

                dbCommand.CommandType = command.Type;
                dbCommand.CommandText = command.Text;
                dbCommand.Parameters.AddRange(command.Parameters);
                return dbCommand.ExecuteReader(CommandBehavior.SequentialAccess);
            }
        }

21. Example

Project: nesper
Source File: BaseDbDriverCommand.cs
View license
protected virtual void CreateOutputParameters()
        {
            try
            {
            /n ..... /n //View Source file for more details /n }

22. Example

Project: nesper
Source File: BaseDbDriverCommand.cs
View license
protected virtual void CreateOutputParameters()
        {
            try
            {
            /n ..... /n //View Source file for more details /n }

23. Example

Project: System.Data.SQLite
Source File: SQLiteCommand.cs
View license
public override object ExecuteScalar()
		{
			using (var reader = ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow))
			{
				do
				{
					if (reader.Read())
						return reader.GetValue(0);
				} while (reader.NextResult());
			}
			return null;
		}

24. Example

Project: MimeKit
Source File: SQLiteCommandBuilder.cs
View license
protected override DataTable GetSchemaTable(DbCommand sourceCommand)
    {
      using (IDataReader reader = sourceCommand.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly))
      {
        DataTable schema = reader.GetSchemaTable();

        // If the query contains a primary key, turn off the IsUnique property
        // for all the non-key columns
        if (HasSchemaPrimaryKey(schema))
          ResetIsUniqueSchemaColumn(schema);

        // if table has no primary key we use unique columns as a fall back
        return schema;
      }
    }

25. Example

View license
private void ExecuteRetried(SqlCommand cmd, LoadFromReader loader, object loadFromReaderParam)
        {
            SqlDataReader reader = null;
            short count = 0;
            while (true)
            {
                try
                {
                    using (SqlConnection conn = new SqlConnection(_connectionString))
                    {
                        cmd.Connection = conn;
                        cmd.Connection.Open();
                        reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                        loader(reader, loadFromReaderParam);
                        break;
                    }
                }
                catch (SqlException se)
                {
                    //
                    // Retry if we deadlocked.
                    // All other exceptions bubble
                    if ((_deadlock == se.Number) && (++count < _retries))
                        continue;

                    throw;
                }
                finally
                {
                    if ((null != reader) && (!reader.IsClosed))
                        reader.Close();
                }
            }
        }

26. Example

Project: NServiceKit
Source File: ProfiledDbCommand.cs
View license
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            if (_profiler == null || !_profiler.IsActive)
            {
                return _cmd.ExecuteReader(behavior);
            }

            DbDataReader result = null;
            _profiler.ExecuteStart(this, ExecuteType.Reader);
            try
            {
                result = _cmd.ExecuteReader(behavior);
                result = new ProfiledDbDataReader(result, _conn, _profiler);
            }
            catch (Exception e)
            {
                _profiler.OnError(this, ExecuteType.Reader, e);
                throw;
            }
            finally
            {
                _profiler.ExecuteFinish(this, ExecuteType.Reader, result);
            }
            return result;
        }

27. Example

Project: Destrier
Source File: Execute.cs
View license
public static void StoredProcedureReader(String storedProcedure, Action<IndexedSqlDataReader> action, dynamic parameters = null, String connectionName = null)
        {
            using (var cmd = Command(connectionName))
            {
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.CommandText = storedProcedure;

                if (parameters != null)
                {
                    Utility.AddParametersToCommand(parameters, cmd);
                }

                using (var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    action(new IndexedSqlDataReader(dr));
                }
            }
        }

28. Example

Project: Destrier
Source File: Execute.cs
View license
public static void StatementReader(String statement, Action<IndexedSqlDataReader> action, dynamic parameters = null, String connectionName = null)
        {
            using(var cmd = Command(connectionName))
            {
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = statement;

                if (parameters != null)
                {
                    Utility.AddParametersToCommand(parameters, cmd);
                }

                using (var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    action(new IndexedSqlDataReader(dr));
                }
            }
        }

29. Example

Project: Destrier
Source File: Execute.cs
View license
public static T Statement<T>(String statement, dynamic parameters = null, String connectionName = null)
        {
            using (var cmd = Command(connectionName))
            {
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = statement;

                if (parameters != null)
                {
                    Utility.AddParametersToCommand(parameters, cmd);
                }

                var type = typeof(T);

                using (var dr = new IndexedSqlDataReader(cmd.ExecuteReader(CommandBehavior.CloseConnection)))
                {
                    if (dr.Read())
                    {
                        if (type.IsValueType || type.Equals(typeof(String)) || type.Equals(typeof(DateTime)))
                        {
                            return dr.Get<T>(0);
                        }

                        return dr.ReadObject<T>(returnNullOnEmpty: true);
                    }
                    else
                    {
                        return default(T);
                    }
                }
            }
        }

30. Example

View license
static SqlDataReader SqlExecuteReaderWithRetry(SqlCommand cmd, CommandBehavior cmdBehavior) {
            bool isFirstAttempt = true;
            DateTime endRetryTime = DateTime.UtcNow;

            while(true) {
                try {
                    if (cmd.Connection.State != ConnectionState.Open) {
                       // reopen the connection
                       // (gets closed if a previous operation throwed a SQL exception with severity >= 20)
                        cmd.Connection.Open();
                    }
                    SqlDataReader reader = cmd.ExecuteReader(cmdBehavior);
                    // the operation succeeded
                    if (!isFirstAttempt) {
                        ClearFlagForClearPoolInProgress();
                    }
                    return reader;
                }
                catch (SqlException e) {
                    if (!CanRetry(e, cmd.Connection, ref isFirstAttempt, ref endRetryTime)) {
                        // just throw, default to previous behavior
                        ThrowSqlConnectionException(cmd.Connection, e);
                    }
                }
                catch (Exception e) {
                   // just throw, we have a different Exception
                   ThrowSqlConnectionException(cmd.Connection, e);
                }
            }
        }

31. Example

Project: anycmd
Source File: RdbDescriptor.cs
View license
public DbDataReader ExecuteReader(string sqlText, CommandType commandType, params DbParameter[] parameters)
        {
            var conn = GetConnection();
            DbCommand cmd = conn.CreateCommand();
            cmd.CommandText = sqlText;
            cmd.CommandType = commandType;
            if (parameters != null && parameters.Length > 0)
            {
                foreach (var item in parameters)
                {
                    cmd.Parameters.Add(item);
                }
            }
            if (conn.State != System.Data.ConnectionState.Open)
            {
                conn.Open();
            }
            DbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            return reader;
        }

32. Example

Project: VoxelSim
Source File: BasicDataServiceTest.cs
View license
protected virtual int ExecQuery(string sql, bool bSingleRow, ProcessRow action)
        {
            int nRecs = 0;
            using (DbConnection dbcon = Connect())
            {
                using (DbCommand cmd = dbcon.CreateCommand())
                {
                    cmd.CommandText = sql;
                    CommandBehavior cb = bSingleRow ? CommandBehavior.SingleRow : CommandBehavior.Default;
                    using (DbDataReader rdr = cmd.ExecuteReader(cb))
                    {
                        while (rdr.Read())
                        {
                            nRecs++;
                            if (!action(rdr))
                                break;
                        }
                    }
                }
            }
            return nRecs;
        }

33. Example

View license
protected virtual int ExecQuery(string sql, bool bSingleRow, ProcessRow action)
        {
            int nRecs = 0;
            using (DbConnection dbcon = Connect())
            {
                using (DbCommand cmd = dbcon.CreateCommand())
                {
                    cmd.CommandText = sql;
                    CommandBehavior cb = bSingleRow ? CommandBehavior.SingleRow : CommandBehavior.Default;
                    using (DbDataReader rdr = cmd.ExecuteReader(cb))
                    {
                        while (rdr.Read())
                        {
                            nRecs++;
                            if (!action(rdr))
                                break;
                        }
                    }
                }
            }
            return nRecs;
        }

34. Example

Project: Pscx
Source File: InvokeAdoCommandCommand.cs
View license
protected override void EndProcessing()
        {
            // do we own the connection? if so, we/n ..... /n //View Source file for more details /n }

35. Example

Project: Integration
Source File: Program.cs
View license
public void ImportBrePolicyVocabulary(string pRootPath, string pSqlServerInstanceName)
            {/n ..... /n //View Source file for more details /n }

36. Example

Project: Susanoo
Source File: DatabaseManager.cs
View license
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
        public virtual DbDataReader ExecuteDataReader(string commandText, CommandType commandType, TimeSpan commandTimeout,
            params DbParameter[] parameters)
        {
            if (string.IsNullOrWhiteSpace(commandText))
                throw new ArgumentNullException(nameof(commandText));

            DbDataReader results = null;

            try
            {
                var open = _explicitlyOpened;
                OpenConnectionInternal();

                using (var command = PrepCommand(Connection, commandText, commandType, commandTimeout, parameters))
                {
                    // If the connection was open before execute was called, then do not automatically close connection.
                    results = open ? command.ExecuteReader() : command.ExecuteReader(CommandBehavior.CloseConnection);
                }
            }
            catch
            {
                if (results != null && !results.IsClosed)
                    results.Dispose();

                // ReSharper disable once ExceptionNotDocumented
                // ReSharper disable once ThrowingSystemException
                throw;
            }

            return results;
        }

37. Example

Project: SmartStoreNET
Source File: CachingCommand.cs
View license
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
		{
			if (!IsCacheable)
			{
				var result = _command.ExecuteReader(behavior);

				if (!_commandTreeFacts.IsQuery)
				{
					_cacheTransactionInterceptor.InvalidateSets(Transaction, _commandTreeFacts.AffectedEntitySets.Select(s => s.Name));
				}

				return result;
			}

			var key = CreateKey();

			object value;
			if (_cacheTransactionInterceptor.GetItem(Transaction, key, out value))
			{
				return new CachingDataReader((CachedRecords)value);
			}

			using (var reader = _command.ExecuteReader(behavior))
			{
				var queryResults = new List<object[]>();

				while (reader.Read())
				{
					var values = new object[reader.FieldCount];
					reader.GetValues(values);
					queryResults.Add(values);
				}

				return HandleCaching(reader, key, queryResults);
			}
		}

38. Example

Project: DNTProfiler
Source File: ProfiledDbCommand.cs
View license
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            DbDataReader originalResult = null;

            var context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, null);
            _profiler.ReaderExecuting(InternalCommand, context);
            _stopwatch.Restart();
            try
            {
                originalResult = InternalCommand.ExecuteReader(behavior);

                var dataSet = new DataSet { EnforceConstraints = false };
                DataRows = new DataTable(tableName: Guid.NewGuid().ToString());
                dataSet.Tables.Add(DataRows);
                dataSet.Load(originalResult, LoadOption.OverwriteChanges, DataRows);

                originalResult = DataRows.CreateDataReader();
            }
            catch (Exception e)
            {
                context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, e);
                _profiler.ReaderExecuting(InternalCommand, context);
                throw;
            }
            finally
            {
                _stopwatch.Stop();
                context = NHProfilerContextProvider.GetLoggedResult(InternalCommand, null, originalResult, _stopwatch.ElapsedMilliseconds, DataRows);
                _profiler.ReaderExecuted(InternalCommand, context);
            }

            return originalResult;
        }

39. Example

Project: Projac
Source File: SqlCommandExecutor.cs
View license
public DbDataReader ExecuteReader(SqlQueryCommand command)
        {
            if (command == null) throw new ArgumentNullException("command");

            var dbConnection = _dbProviderFactory.CreateConnection();
            dbConnection.ConnectionString = _settings.ConnectionString;
            dbConnection.Open();
            try
            {
                using (var dbCommand = dbConnection.CreateCommand())
                {
                    dbCommand.Connection = dbConnection;
                    dbCommand.CommandTimeout = _commandTimeout;

                    dbCommand.CommandType = command.Type;
                    dbCommand.CommandText = command.Text;
                    dbCommand.Parameters.AddRange(command.Parameters);
                    return dbCommand.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SequentialAccess);
                }
            }
            catch
            {
                dbConnection.Close();
                throw;
            }
        }

40. Example

View license
public override string GetUserNameByEmail(string email)
        {
            SecUtility.CheckParame/n ..... /n //View Source file for more details /n }

41. Example

Project: referencesource
Source File: SQLRoleProvider.cs
View license
private void  AddUsersToRolesCore(SqlConnection conn, string usernames, string roleNames)
        {
/n ..... /n //View Source file for more details /n }

42. Example

Project: referencesource
Source File: SQLRoleProvider.cs
View license
private void RemoveUsersFromRolesCore(SqlConnection conn, string usernames, string roleNames)
      /n ..... /n //View Source file for more details /n }

43. Example

Project: referencesource
Source File: SQLRoleProvider.cs
View license
public override  string [] GetAllRoles(){
            try {
                SqlConnectionHolder hold/n ..... /n //View Source file for more details /n }

44. Example

View license
private byte[] LoadPersonalizationBlob(SqlConnection connection, string path, string userName) {
   /n ..... /n //View Source file for more details /n }

45. Example

Project: referencesource
Source File: SqlTrackingQuery.cs
View license
public bool TryGetWorkflow(Guid workflowInstanceId, out SqlTrackingWorkflowInstance workflowInstance)
        {
            SqlCommand cmd = BuildCommand(workflowInstanceId);
            SqlDataReader reader = null;
            workflowInstance = null;

            try
            {

                cmd.Connection = GetConnection();
                reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                //
                // There will only be 1 row
                if (reader.Read())
                {
                    workflowInstance = BuildInstance(reader);
                    return true;
                }
                else
                    return false;
            }
            finally
            {
                if (null != reader)
                    reader.Close();

                if (null != cmd && null != cmd.Connection && ConnectionState.Closed != cmd.Connection.State)
                    cmd.Connection.Close();
            }
        }

46. Example

View license
private void ImportBrePolicyVocabulary()
        {
            String[] files;
            try
     /n ..... /n //View Source file for more details /n }

47. Example

View license
private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc) {
 /n ..... /n //View Source file for more details /n }

48. Example

View license
private string GetPasswordFromDB( string       username,
                                          s/n ..... /n //View Source file for more details /n }

49. Example

Project: referencesource
Source File: SQLRoleProvider.cs
View license
public override  string [] GetRolesForUser(string username)
        {
            SecUtility.CheckPa/n ..... /n //View Source file for more details /n }

50. Example

Project: referencesource
Source File: SQLRoleProvider.cs
View license
public override  string [] GetUsersInRole(string roleName)
        {
            SecUtility.CheckPar/n ..... /n //View Source file for more details /n }