mutli threaded application shuts down all copies of access when issueing quit command

S

Steven Thomas

I have a windows service that uses office xp automation. Here is the
code
---------------------------------------
Public Sub CAccessSnapShot()
Try
Dim objAccess As New Access.Application()
Dim vSQLText, vThreadName As String
Try
vThreadName = Thread.CurrentThread.Name
cFunctions.WriteEventLog("starting report on thread: "
& pDBType)
Dim dtSQLText As DataTable
' GET THE SQL ASSOCIATED WITH THIS REPORT
dtSQLText = cFunctions.GetSQL(pReportRefNum,
pQConnectionString)
vSQLText = CStr(dtSQLText.Rows(0).Item("SQLText"))
Dim strMDBName, strSNPName, strAccessFuncNm As String
' GET THE NAME OF THE TEMPORARY MDB AND MAKE A COPY
TO WORK WITH
strMDBName = cFunctions.GetNewFileName(".mdb")
strMDBPath = pInputFileDir + strMDBName
System.IO.File.Copy(pInputFileDir + pInputFileName,
pInputFileDir + strMDBName)
' OPEN THE NEW COPY OF THE MDB
objAccess.OpenCurrentDatabase(pInputFileDir +
strMDBName)
' GET THE NEW NAME OF THE SNAP FILE
strSNPName = cFunctions.GetNewFileName(".snp")
strAccessFuncNm = "rpt" + pReportName
' RUN THE FUNCTION FROM ACCESS TO CREATE THE REPORT
SNAPSHOT
objAccess.Run("RunReports", pReportName, vSQLText,
pOutputFileDir, strSNPName, pConnectString)
' SHUT DOWN ACCESS AND RELEASE THE COPY FROM MEMORY
objAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
' ------
System.Runtime.InteropServices.Marshal.ReleaseComObject(objAccess)
' UPDATE THE QUEUE WITH THE SNAP SHOT NAME AND DELETE
THE COPY OF THE MDB
cFunctions.WriteEventLog("complete report on thread: "
& vThreadName)
cFunctions.UpdateRptComplete(pReportRefNum,
strSNPName, pQConnectionString)
System.IO.File.Delete(strMDBPath)
'RaiseEvent ThreadDone(pDBType)
Catch errorVariable As Exception
'Error trapping
cFunctions.UpdateReportError(pReportRefNum,
errorVariable.Message.ToString, pQConnectionString)
cFunctions.WriteEventLog("GPReportServer.NET-Error: "
& errorVariable.Message.ToString)
objAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
' -----
System.Runtime.InteropServices.Marshal.ReleaseComObject(objAccess)
Finally
RaiseEvent ThreadDone(pDBType, vThreadName)
End Try
'CType(state, AutoResetEvent).Set()
Catch
Catch errorVariable As Exception
'Error trapping
cFunctions.UpdateReportError(pReportRefNum,
errorVariable.Message.ToString, pQConnectionString)
cFunctions.WriteEventLog("GPReportServer.NET-Error: " &
errorVariable.Message.ToString)
End Try
End Sub

-----------------------------------------------------
I have a driver sub routine that creates a set of threads. Then on
each tread it calls this sub if there is a request for an access
report. He problem is if 2 or more threads are running at the same
time, when the first thread ends and issues the quit, it seems to
affect all instances of access in memory. The all stop running. How
can I issue the quit to just the thread this sub is running on???
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (Steven Thomas) scripsit:
[...]

Double post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top