Closing out a database connection through Active X

TheWizardofInt

Well-known member
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
I am having a problem with an ActiveX.dll which doesnt seem to close out.

In order for the program to work, I open a dBaseIV file like so:

Code:
        Dim myConnection As OleDb.OleDbConnection
        Dim myCommand As OleDb.OleDbCommand
        Dim myDataReader As OleDb.OleDbDataReader
        Dim strSQLQuery As String
        Dim sAccNo As String
        Dim i As Integer
        Dim sName As String
        Dim sRecID As String
        Dim sSeekFor As String = Request("ID")
        If Not Page.IsPostBack Then
            query the contact1 database
            strSQLQuery = "Select * from contact1 WHERE RecID =" & Session("spassrec") & ""
            myConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=d:\asp\gm57\common;Extended Properties=dBase IV")
            myCommand = New OleDb.OleDbCommand(strSQLQuery, myConnection)
            Try
                myConnection.Open()
            Catch ex1 As Exception
                    Response.Write(ex1.GetType)
                    Response.Write("********")
                    Response.Write(ex1.ToString)
                    myCommand = Nothing
                    myConnection.Close()
                    myConnection = Nothing
                    Exit Sub
            End Try

             Get a new datareader from our command
            myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
            If myDataReader.Read Then
              do stuff
            End if
        mydatareader.close
        myconnection.close
        mydatareader=nothing
        myconnection=nothing

Then I write to the same location through a dynamic link library. Writing with the ADO isnt an option.

Then I try to load the data again, and once in a while the program tells me that it cant open the database, either for an unhandled exception or because it is opened exclusively by another program.

I think that I am either missing a command with the ADO commands for openning the data, or (more likely) the ActiveX dll isnt closing out properly. I just set it to nothing.

Any ideas?
 
Im not sure where the ActiveX comes into play - maybe you could let us know more about it?

I dont see anything wrong with your code off-hand. The connection is being closed and that should be all you need. Settign to Nothing is nice, but isnt the same as in VB6 - it wont really eliminate the object from memory immediately. Closing is the important part.

Do you have any more details on the unhandled exception? Where is it happening exactly (which line of code)? The "exclusively opened by another user" error is usually when the database is openened through some other tool (such as when you open an MDB in Access). Im not that familiar with dbase so I cant really guess.

-Nerseus
 
You see, there is the rub.

There is really no way to close the active X object. It is just a reference to a .dll

You would set it up as a COM reference, you would refer to it with an object, then you would be done with it.

You can set it to nothing, but the object it refers to doesnt allow a .close

Is there a manual way to close the object?
 
Im not sure what youre talking about... The OleDb.OleDbDataReader object is NOT an ActiveX component. If youre using an ActiveX DLL somewhere, I dont see the code for it and I cant help if I dont know what code youre running. The code you posted creates a connection and reads some data then closes the connection - no problems that I can see (offhand).

-Nerseus
 
Ok, I am not explaining this correctly

I open a database with the code shown, in order to find a record using ADO.

I close the database, then reopen it to write to it, with an ActiveX.dll

I try to close the ActiveX.dll but it keeps the connection to the database open, as it is obviously not closing out properly. I know this because sometimes, when I try to open the database again with the code, above, it gives me an unhandled Exception 8000000 or something, which refers to a thread being open.

I refer to the ActiveX.dll this way:

Code:
      Dim objGMApp As IWGMProcs.clsGMApp
      objGMApp = New IWGMProcs.clsGMApp()

Where IWGMProcs is the name of the .dll and cldGMApp is a class within it.

What I need to do is close out the objGMApps with something more effective than setting it to nothing.

Thanks
 
@TheWizardofInt, by any chance, have you resolved this as I am having the same problem.

I am trying to do the same as you and after a certain amount of dll acces times, the dll code doesnt seem to work.

Thanks
 
What I did was to dispose the object immediately after I ran it

Code:
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        CODEGEN: This procedure is required by the Web Services Designer
        Do not modify it using the code editor.
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        If Not <each .dll in use> Is Nothing Then
            <this dll>.Dispose()
            <This .dl> = Nothing
        End If
        MyBase.Dispose(disposing)
    End Sub
 
Back
Top