System.Data.Common.DbCommand.OpenConnection()

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

7 Examples 7

1. Example

Project: Sequelocity.NET
Source File: SequelocityDotNet.cs
public static DbTransaction BeginTransaction( this DbCommand dbCommand )
        {
            dbCommand.OpenConnection();

            DbTransaction transaction = dbCommand.Connection.BeginTransaction();

            dbCommand.SetTransaction( transaction );

            return transaction;
        }

2. Example

Project: Sequelocity.NET
Source File: SequelocityDotNet.cs
public static DbTransaction BeginTransaction( this DbCommand dbCommand, IsolationLevel isolationLevel )
        {
            dbCommand.OpenConnection();

            DbTransaction transaction = dbCommand.Connection.BeginTransaction( isolationLevel );

            dbCommand.SetTransaction( transaction );

            return transaction;
        }

3. Example

Project: Sequelocity.NET
Source File: SequelocityDotNet.cs
public static int ExecuteNonQuery( this DatabaseCommand databaseCommand, bool keepConnectionOpen = false )
        {
            int numberOfRowsAffected;

            try
            {
                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandPreExecuteEventHandlers( databaseCommand );

                databaseCommand.DbCommand.OpenConnection();

                numberOfRowsAffected = databaseCommand.DbCommand.ExecuteNonQuery();

                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandPostExecuteEventHandlers( databaseCommand );
            }
            catch ( Exception exception )
            {
                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandUnhandledExceptionEventHandlers( exception, databaseCommand );

                throw;
            }
            finally
            {
                if ( keepConnectionOpen == false )
                {
                    databaseCommand.DbCommand.CloseAndDispose();

                    databaseCommand.DbCommand = null;
                }
            }

            return numberOfRowsAffected;
        }

4. Example

Project: Sequelocity.NET
Source File: SequelocityDotNet.cs
public static object ExecuteScalar( this DatabaseCommand databaseCommand, bool keepConnectionOpen = false )
        {
            object returnValue;

            try
            {
                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandPreExecuteEventHandlers( databaseCommand );

                databaseCommand.DbCommand.OpenConnection();

                returnValue = databaseCommand.DbCommand.ExecuteScalar();

                if ( returnValue == DBNull.Value )
                    returnValue = null;

                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandPostExecuteEventHandlers( databaseCommand );
            }
            catch ( Exception exception )
            {
                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandUnhandledExceptionEventHandlers( exception, databaseCommand );

                throw;
            }
            finally
            {
                if ( keepConnectionOpen == false )
                {
                    databaseCommand.DbCommand.CloseAndDispose();

                    databaseCommand.DbCommand = null;
                }
            }

            return returnValue;
        }

5. Example

Project: Sequelocity.NET
Source File: SequelocityDotNet.cs
public static DataSet ExecuteToDataSet( this DatabaseCommand databaseCommand, bool keepConnectionOpe/n ..... /n //View Source file for more details /n }

6. Example

Project: Sequelocity.NET
Source File: SequelocityDotNet.cs
public static void ExecuteReader( this DatabaseCommand databaseCommand, Action<IDataRecord> dataRecordCallback, bool keepConnectionOpen = false )
        {
            try
            {
                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandPreExecuteEventHandlers( databaseCommand );

                databaseCommand.DbCommand.OpenConnection();

                using ( DbDataReader dbDataReader = databaseCommand.DbCommand.ExecuteReader() )
                {
                    while ( dbDataReader.HasRows )
                    {
                        while ( dbDataReader.Read() )
                        {
                            dataRecordCallback.Invoke( dbDataReader );
                        }

                        dbDataReader.NextResult();
                    }
                }

                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandPostExecuteEventHandlers( databaseCommand );
            }
            catch ( Exception exception )
            {
                Sequelocity.ConfigurationSettings.EventHandlers.InvokeDatabaseCommandUnhandledExceptionEventHandlers( exception, databaseCommand );

                throw;
            }
            finally
            {
                if ( keepConnectionOpen == false )
                {
                    databaseCommand.DbCommand.CloseAndDispose();

                    databaseCommand.DbCommand = null;
                }
            }
        }

7. Example

Project: Sequelocity.NET
Source File: SequelocityDotNet.cs
public static IEnumerable<T> ExecuteReader<T>( this DatabaseCommand databaseCommand, Fun/n ..... /n //View Source file for more details /n }