I have a program the writing many lines to a table in enterprise geodatabase.
I all the geodatabase example I could find you always use
using (Geodatabase geodatabase = new Geodatabase...
This will reopen the enterprise geodatabse for each single line I write to the log.
Is this the correct way to do it?
Can I keep the Geodatabse open?
Thanks
It's hard to visualize without code, but I assume you are writing out rows to a geodatabase in some kind of loop, right? If so, just open the geodatabase outside of the loop.
Think about this case:
I have a program that runs 10 GP tools one after another. Sometime I run them all, sometime I skip one or two and sometime some of them fail.
I would like to get 10 messages in my log table (Tool 1 success, tool 2 skip, tool 3 fail etc.)
I use similar code to this: ProSnippets Geodatabase · Esri/arcgis-pro-sdk Wiki · GitHub to write to the log table (all other examples I found is slimier). This code will open sde oracle database 10 times. This is very expensive...
I would like to keep the Table object open and use it again and again.
What is the correct way here?
Thanks
Hi Mody,
The easiest way would be to add the table to the table of contents in the map and access it from there. This will keep it open.
Another way to do this would be to create a class like the following:
class MyLogger : IDisposable {
private Table _logTable = null; //instance variable – pins the table when assigned to prevent it going out of scope
// Initialize the logger object
internal Task InitializeAsync() {
QueuedTask.Run(() => {
Using(var gdb = new Geodatabase(...) {
//assign it
_logTable = gdb.OpenDataset<Table>(…)
}
});
}
//use it
Internal Task<bool> LogAsync(string message)
{
//declare on the UI is ok
Var editop = new EditOperation() { ….
//will be called on the QueuedTaskRun
editOp.Callback( context => {
//do your thing…using the instance member
Using(var rb =_logTable.CreateRowBuffer()) {
}
}, _logTable);
return editOp.ExecuteAsync();
}
//clean up
Private void Dispose() {
_logTable.Dispose();
_logTable = null;
}
}
I hope this helps,
--Rich