Can't open FGDB in console application

1847
2
Jump to solution
07-29-2013 09:22 AM
Highlighted
New Contributor
Hi, Getting back on the horse after a couple of years in a non-technical position. I am trying to write a console application that iterates through a fc in a FGDB and updates values. Having trouble opening the FGDB. The code below binds, checks out, and verifies that I have checked out a desktop advanced license, but fails on the very last line, opening the FGDB (the first objects command).

Win7, 10.1 Desktop, c# Visual Studio Express 2010
Error: Error HRESULT E_FAIL has been returned from a call to a COM component (no details)
Console says license checkout was successful

thanks in advance


static void OpenFGDB()
{

//get and verify the license
ESRI.ArcGIS.esriSystem.AoInitialize aoInit = null;
try
{
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
aoInit = new AoInitializeClass();
if (aoInit.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeAdvanced) == esriLicenseStatus.esriLicenseAvailable)
{
esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
if (licStatus == esriLicenseStatus.esriLicenseCheckedOut)
{
Console.WriteLine("ArcGIS Advnaced License Checkout Successful.");
}
else
{
Console.WriteLine("ArcGIS Advanced License is availble but could not be checked out, program exiting.");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
Environment.Exit(0);
}
}
else
{
Console.WriteLine("ArcGIS Advanced License not available, program exiting.");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
Environment.Exit(0);
}
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}


//open the fgdb
IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile("@C:\temp\test.gdb", 0); //fails here

}
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Regular Contributor III
IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();


You should never use New to instantiate an instance of a singleton object.  Use the Activator class instead.  See the following help topic for more info.

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/#/Interacting_with_singleton_objec...

View solution in original post

Reply
0 Kudos
2 Replies
Highlighted
Regular Contributor III
IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();


You should never use New to instantiate an instance of a singleton object.  Use the Activator class instead.  See the following help topic for more info.

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/#/Interacting_with_singleton_objec...

View solution in original post

Reply
0 Kudos
Highlighted
New Contributor
IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();


You should never use New to instantiate an instance of a singleton object.  Use the Activator class instead.  See the following help topic for more info.

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/#/Interacting_with_singleton_objec...


My issue was actually related to creating a new fgdb vs referencing an existing one, but your response got me on the path and bettered my code in other ways.  Thank you.
Reply
0 Kudos