closing objects confusion

hog

Well-known member
Joined
Mar 17, 2003
Messages
984
Location
UK
I have an object which has various methods that manipulate data in datasets, some of which get written back to the database.

Where I open a connection I always ensure that the Finally statement includes a test to see if the connection is open and closes it accordingly.

Likewise I do the same with Update connections thus:

Code:
  Finally

            If m_odaContract.UpdateCommand.Connection.State.Open Then

                 close the connection

                m_odaContract.UpdateCommand.Connection.Close()

            End If

        End Try

In the procedure where the above code belongs, there is some code that runs other methods and if they return True then the update code section runs.

I am finding that if that section returns False the execution quite rightly jumps to the Finally section and performs that test. But the test is showing the Open state has the value 1 and therefore tries to execute the Close method which then error saying the object is not set?

This is right as the code that performs the update has been bypassed so the object would not be set.

Question is why is the open statement returning that it is open? I have been through my code and all the connection.close calls are present?
 
Hog,
There are three different objects that can not be set in the method, the dataadapter, the connection and the command objects. Can you sort through which is not instantiated?
As a by the way, the connection does not need to be explicity closed when you are using a dataadapter. It returns the connection to its baseline state when it finishes using the connection.

Jon
 
jfackler, thanks. I could not track this down, so just removed the code that was trying to close the data adapter following your advice above.

Cheers :-)
 
Back
Top