Select to view content in your preferred language

Cannot close a GeoDatabase after creating it.

3903
6
Jump to solution
02-21-2013 11:57 PM
MaoEdgar
Emerging Contributor
Hi,

I created a GeoDatabase and added a table and added a field and I cannot close it. Can anyone help on this?

Attached is the sample, the version of dll is 1.2.0.136.

Thanks,
Edgar
0 Kudos
1 Solution

Accepted Solutions
VinceAngelo
Esri Esteemed Contributor
Why are you opening the same geodatabase twice?

The documentation indicates that FileGDBAPI::Geodatabase::GetChildDatasets would
be used to get the list of tables.

- V

View solution in original post

0 Kudos
6 Replies
VinceAngelo
Esri Esteemed Contributor
Is there a particular reason you're not using the 1.3 API release?  Given a new
product with a standalone library, I can't see any.

If your application is 10 lines long, then you are drastically reducing the number
of folks who will look at it by posting as a zip file (as opposed to including it in
a CODE block within the post).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Esri.FileGDB;
using System.IO;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            //1.2.0.136
            Geodatabase.Create("a.gdb");
            Geodatabase geodatabase = Geodatabase.Open("a.gdb");
            string template = File.ReadAllText("../../template.xml");
            string tableDef = template.Replace("%Name%", "myTable").Replace("%ShapeType%", "esriGeometryPoint");
            Table table = geodatabase.CreateTable(tableDef);
            string fieldTemplate = File.ReadAllText("../../fieldTemplate.xml");
            table.AddField(fieldTemplate.Replace("%Name%", "pointField"));
            table.Close();
            //stop here
            geodatabase.Close();
        }
    }
}


If you don't ever test error results, any number of bad things can happen.

Have you tried eliminating the AddField or AddField and CreateTable steps?

I don't see a Close request on Table in the C++ documentation.

- V
0 Kudos
MaoEdgar
Emerging Contributor
Thanks for your answer, I comment the Geodatabase.Create("a.gdb") or I change it to Geodatabase.Create("a.gdb").Close() and it works fine, however, there seems to be a bug in Opening the database? Here are the secnerios,

 
var b = Geodatabase.Open("a.gdb");
var a = Geodatabase.Open("a.gdb");
//stops here
a.Close();
b.Close();


var b = Geodatabase.Open("a.gdb");
var a = Geodatabase.Open("a.gdb");
//works fine.
b.Close();
a.Close();

Is the Close method supposed to be called in a specified sequence?
0 Kudos
MaoEdgar
Emerging Contributor
One more question, is there any way to get the table names from a database? It seems that I must specify a table name before querying it.

Thanks,
Edgar
0 Kudos
VinceAngelo
Esri Esteemed Contributor
Why are you opening the same geodatabase twice?

The documentation indicates that FileGDBAPI::Geodatabase::GetChildDatasets would
be used to get the list of tables.

- V
0 Kudos
MaoEdgar
Emerging Contributor
Thanks for the answer about my last question, but can't I open the same database twice? It's a static method I thought I could do that but failed on the sequence.

Regards,
Edgar
0 Kudos
VinceAngelo
Esri Esteemed Contributor
You *shouldn't* open anything more than once, especially when it provides
multiple concurrent table handles as part of a single open.  But the fact that
doing so exposes a bug in the Linux implementation was already discovered
earlier this month.

- V
0 Kudos