|
Norman Neubert
Posts: 19
Joined: 2022-06-09
|
Hello,
we maintain a COM add-in built with Add-in Express for Office and .NET (currently 10.2.4714), registered for both Excel and Access (SupportedApps = ohaExcel Or ohaAccess). In Access we only subscribe to ADXAccessAppEvents.OpenDatabase. In that handler we do real work on the database that was just opened: we read and write custom DAO database properties (CurrentDb.Properties, create/delete), we query our own SQL Server backend, and in one branch we call Application.CloseCurrentDatabase().
Some customers report that Access databases on network shares occasionally end up in an inconsistent state and have to be repaired by Access. One user documented the sequence: while saving a query, the database closes by itself; on the next open, Access reports "Unrecognized database format", then repairs the file into a new database. We have not been able to reproduce it.
From your forum post at FID=1&TID=15391 we understand that Access has no application-level events and that Add-in Express simulates OpenDatabase, CloseDatabase, AccessIdle and CurrentObjectChanged by polling with a timer. That leads to four questions:
1. Can OpenDatabase fire for a database that is already open? Specifically: if reading CurrentProject.IsConnected or CurrentProject.FullName fails or returns an unexpected value in a single polling cycle — for example because Access is busy — does Add-in Express then raise CloseDatabase followed by OpenDatabase for the very same file, without the user having switched databases? If so, what is the recommended way to tell a genuine database open from such a repeated notification?
2. What exactly does AccessIdle mean? Does it indicate that Access is actually idle and not processing anything, or simply that a polling cycle passed without a detected change? We are asking because we would like to know whether AccessIdle is a safe moment to perform write access (creating and deleting DAO database properties) on the currently open database.
3. Is it supported at all to write to the open database from inside these event handlers? Our handler writes DAO database properties and, in one case, calls Application.CloseCurrentDatabase() directly from the OpenDatabase handler. Is there a recommended pattern for deferring such work to a point where Access is guaranteed not to be in the middle of an operation?
4. Can the Access polling be configured? Is there a supported way to change the polling interval, or to suppress the Access polling entirely if an add-in only needs OpenDatabase? Does setting ADXAccessAppEvents.Enabled = False stop the polling itself, or only the raising of the events?
Thanks in advance,
Norman |
|
|
Andrei Smolin
Add-in Express team
Posts: 19240
Joined: 2006-05-11
|
Hello Norman,
I'm terribly sorry for missing your post; I assume I overlooked it for an unknown reason.
I'll study the .NET code to get answers to all/some of your questions and respond next Monday.
I suggest that you make sure you release *every* COM object you create in your code. This *especially* relates to DAO and ADO; so that construct similar to db.TableDefs.Item(i) - this is a raw code given in VB - is split in this way:
theTables = db.TableDefs
theTable = theTables.Item(i)
' using theTable
Marshal.ReleaseComObject(theTable)
Marshal.ReleaseComObject(theTables)
Find more on releasing COM objects in https://www.add-in-express.com/forum/read.php?FID=5&TID=16801
Regards from Poland (GMT+1),
Andrei Smolin
Add-in Express Team Leader |
|
|
Norman Neubert
Posts: 19
Joined: 2022-06-09
|
Hi Andrei,
no problem, thank you for your reply on this :)
Looking forward to your answer next week.
Kind regards and have a nice weekend
Norman |
|
|
Norman Neubert
Posts: 19
Joined: 2022-06-09
|
Hi Andrei,
do you have an update for me on this?
Thanks in advance
Norman |
|
|
Andrei Smolin
Add-in Express team
Posts: 19240
Joined: 2006-05-11
|
Hello Norman,
I'm sorry for the delay. Unfortunately, it took me much more time than I expected to get to the code.
Norman Neubert writes:
1. Can OpenDatabase fire for a database that is already open?
I'm unable to respond to this question. To help you find the answer yourself I send you a separate email with the complete method that handles the timer's tick.
Norman Neubert writes:
2. What exactly does AccessIdle mean?
The code of that method shows this event is raised if there are no detected changes.
Norman Neubert writes:
3. Is it supported at all to write to the open database from inside these event handlers?
I'm not really sure.
Norman Neubert writes:
4. Can the Access polling be configured?
There's no supported way. But you can use late binding to change the state of the private variables the ADXAddinModule class uses for polling; see my email. An example of such a call is this:
typeof(Application).InvokeMember("FormActivated", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static, null, null, new object[] { false, true });
You can use the following search query to find other examples: https://www.add-in-express.com/search-addin.php?x=0&y=0&q=%22InvokeMember%22+%22NonPublic%22.
Regards from Poland (GMT+1),
Andrei Smolin
Add-in Express Team Leader |
|