Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am having a problem with an ActiveX.dll which doesn't seem to close out.

 

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

 

       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 isn't an option.

 

Then I try to load the data again, and once in a while the program tells me that it can't 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 isn't closing out properly. I just set it to nothing.

 

Any ideas?

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

  • *Experts*
Posted

I'm not sure where the ActiveX comes into play - maybe you could let us know more about it?

 

I don't 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 isn't the same as in VB6 - it won't 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). I'm not that familiar with dbase so I can't really guess.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

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 doesn't allow a .close

 

Is there a manual way to close the object?

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

  • *Experts*
Posted

I'm not sure what you're talking about... The OleDb.OleDbDataReader object is NOT an ActiveX component. If you're using an ActiveX DLL somewhere, I don't see the code for it and I can't help if I don't know what code you're running. The code you posted creates a connection and reads some data then closes the connection - no problems that I can see (offhand).

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

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:

 

     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

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

  • 2 years later...
Posted

@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 doesn't seem to work.

 

Thanks

Posted

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

 


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

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...