Access 2002 instance not closing from .NET call

  • Thread starter Thread starter Rich Wallace
  • Start date Start date
R

Rich Wallace

Hi all,

I have an app that contains the following code....

----------------------------------------------------------------------------
------------------------------
Public Sub CreateNewDatabase(ByVal DbFile As String, ByVal sLots As String)

Dim catNewDB As New ADOX.Catalog
Dim oAccApp As New Access.Application

catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="
& DbFile)
catNewDB.ActiveConnection.Close()
catNewDB = Nothing

Try
oAccApp.OpenCurrentDatabase(DbFile)

oAccApp.ImportXML("http://localhost/export/Export/tblClosing.xsd",
AcImportXMLOption.acStructureOnly)
ExportData(DbFile, oAccApp)
Catch ex As Exception
EventLog.WriteEntry("Export", ex.Message)
Finally
oAccApp.CloseCurrentDatabase()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccApp)
oAccApp = Nothing
End Try

End Sub

Although I use the ReleaseComObject method once I'm done working with the
MDB file, I still have MSACCESS.EXE running in the processes of my system,
and the MDB is locked and I have an LDB that will not release.

Any ideas on what may cause this?

VS.NET 2003
IIS 5.0
Access 2002

TIA
-Rich
 
Rich,

Why do you send classic Ado problems to an AdoNet newsgroup.
They are not the same, see my message tree lows below to CES for that.

Cor
 
Rich,

The Access.Application object has a Quit method that should be called before
you release the reference if you want the application to actually exit.

HTH,
Nicole
 
¤ Why do you send classic Ado problems to an AdoNet newsgroup.
¤ They are not the same, see my message tree lows below to CES for that.

Because he's using it with VB.NET via interop which could very well be different than when running
it under Classic VB.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Paul,
Because he's using it with VB.NET via interop which could very well be different than when running
it under Classic VB.
Therefore you do not see this message from me in the VBnet
dotnet.language.VB newsgroup or the dotnet.General newsgroup, (Although I
often ask why not AdoNet) however it is in my opinion surely not an ADONET
newsgroup question.

Cor
 
¤ Paul,
¤
¤ > Because he's using it with VB.NET via interop which could very well be
¤ different than when running
¤ > it under Classic VB.
¤ >
¤ Therefore you do not see this message from me in the VBnet
¤ dotnet.language.VB newsgroup or the dotnet.General newsgroup, (Although I
¤ often ask why not AdoNet) however it is in my opinion surely not an ADONET
¤ newsgroup question.

Probably dotnet.framework.interop.

Don't send him to the Classic VB newsgroups. The mere mention of .NET over there and they will punt
him back here.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Cor, Paul,

Please forgive me, I was under pressure and didn't think before I posted.
It is a call under .NET, but I can see Cor's point. Consider it a lesson
learned.

Thank you,
-Rich

 
Hi Nicole,

I added this to my code however, the issue still remains.

Thank you for the reply.
 
¤ Hi Nicole,
¤
¤ I added this to my code however, the issue still remains.
¤

ADOX may be partly responsible. Since you're already using automation you may want to just use
Access to create your database in order to avoid other connections to the database.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
What's odd is when I step through the process in debug, the LDB is dropped
after I use ActiveConnection.Close().

Here's a view of what I do...

-------------------------------------------------------------
Dim catNewDB As New ADOX.Catalog
Dim oAccApp As New Access.Application

'Create New MDB
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="
& DbFile)
catNewDB.ActiveConnection.Close() -- LDB disappears on this line
catNewDB = Nothing

Try
oAccApp.OpenCurrentDatabase(DbFile) --LDB file reappears
oAccApp.ImportXML("http://localhost//Export/tblSchema.xsd",
AcImportXMLOption.acStructureOnly)
ExportData(sLots, DbFile, oAccApp)
Catch ex As Exception
EventLog.WriteEntry("Export", ex.Message)
Finally
oAccApp.CloseCurrentDatabase()
oAccApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccApp)
oAccApp = Nothing --LDB still exists
End Try
-------------------------------------------------------------

After all is said and done, the LDB remains and any operations attempted on
the new file receive the file sharing error.

-Rich
 
¤ What's odd is when I step through the process in debug, the LDB is dropped
¤ after I use ActiveConnection.Close().
¤
¤ Here's a view of what I do...
¤
¤ -------------------------------------------------------------
¤ Dim catNewDB As New ADOX.Catalog
¤ Dim oAccApp As New Access.Application
¤
¤ 'Create New MDB
¤ catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="
¤ & DbFile)
¤ catNewDB.ActiveConnection.Close() -- LDB disappears on this line
¤ catNewDB = Nothing
¤
¤ Try
¤ oAccApp.OpenCurrentDatabase(DbFile) --LDB file reappears
¤ oAccApp.ImportXML("http://localhost//Export/tblSchema.xsd",
¤ AcImportXMLOption.acStructureOnly)
¤ ExportData(sLots, DbFile, oAccApp)
¤ Catch ex As Exception
¤ EventLog.WriteEntry("Export", ex.Message)
¤ Finally
¤ oAccApp.CloseCurrentDatabase()
¤ oAccApp.Quit()
¤ System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccApp)
¤ oAccApp = Nothing --LDB still exists
¤ End Try
¤ -------------------------------------------------------------
¤
¤ After all is said and done, the LDB remains and any operations attempted on
¤ the new file receive the file sharing error.
¤

Well if all else fails you can terminate Access using API function calls:

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Int32
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg
As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32

Public Function TerminateAccess()

Dim ClassName As String
Dim WindowHandle As Int32
Dim ReturnVal As Int32
Const WM_QUIT = &H12

ClassName = "OMain"
WindowHandle = FindWindow(ClassName, Nothing)

If WindowHandle Then
ReturnVal = PostMessage(WindowHandle, WM_QUIT, 0, 0)
End If

End Function


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Rich,

I'm unable to reproduce the problem. Could it perhaps be that your
ExportData method is leaving a reference hanging? Also, why not simply
create the database using Access.NewCurrentDatabase?

HTH,
Nicole
 
I thought of something like that but the MSACCESS.EXE instance will be
running on my web server as this is ASP.NET, and I may have several users
trying to perform the operation and I don't want to kill other users if
they're trying to create their own DB.
 
¤ I thought of something like that but the MSACCESS.EXE instance will be
¤ running on my web server as this is ASP.NET, and I may have several users
¤ trying to perform the operation and I don't want to kill other users if
¤ they're trying to create their own DB.
¤

Running on the web server? Well now you're truly living dangerously. ;-)

INFO: Considerations for Server-Side Automation of Office
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top