IDisposable Member Implementation


    public class SqlFunction: IDisposable
    {
        String connectionString="";
        SqlConnection connection = null; 
        SqlCommand command = null; 
        SqlDataAdapter da = null; 
        SqlTransaction transaction = null;
        Boolean useSqlTransaction = false;

        #region
           //Other code
        #endregion

        #region iDisposable_mthods

            private bool disposed = false;

            public void Dispose()
            {
                CleanUp(true);
                GC.SuppressFinalize(this);
            }

            private void CleanUp(bool disposing)
            {
                // Be sure we have not already been disposed!
                if (!this.disposed)
                {
                    // If disposing equals true, dispose all
                    // managed resources.
                    if (disposing)
                    {
                        // Dispose managed resources.
                        connection.Dispose(); c
                        ommand.Dispose();  
                        da.Dispose(); 
                        transaction.Dispose();
                    }
                    // Clean up unmanaged resources here.
                }
                disposed = true;
            }

            ~SqlFunction()
            {
                CleanUp(false);
            }

        #endregion
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s