Select to view content in your preferred language

error opening Workspace

1272
4
02-12-2013 11:40 AM
TerryGiles
Frequent Contributor
I recently upgraded a server w/ Engine installed to 10.1 sp1 from 10.0.  I have some code in a simple console app that creates XY events from a spreadsheet and then writes those features into a SDE instance.  Since the upgrade, the code bombs when I try to open a workspace from the spreadsheet - code below.  Any ideas what I'm missing or may have changed from 10.0?

Thanks, TG

            Console.WriteLine("Import Starting - " + DateTime.Now.ToShortTimeString());
            try
            {
                //Open XLS as table & make XY layer
                factoryType = Type.GetTypeFromProgID("esriDataSourcesOleDB.ExcelWorkspaceFactory");

                WSFac = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                
                Console.WriteLine(WSFac.IsWorkspace(strXLSarchive));
                Console.WriteLine("Looking for " + strXLSarchive);
                Console.WriteLine("does file exists " + File.Exists(strXLSarchive).ToString());

                WS = WSFac.OpenFromFile(strXLSarchive, 0);   <--  falls into the Catch block here
                Console.WriteLine("WS opened");

                fWS = (IFeatureWorkspace)WS;
                table = fWS.OpenTable(strXLSsheet);
                ds = table as IDataset;

                XYProps = new XYEvent2FieldsPropertiesClass()
                {
                    XFieldName = strXField,
                    YFieldName = strYField
                };

                XYName = new XYEventSourceNameClass()
                {
                    EventProperties = XYProps,
                    SpatialReference = srWGS84,
                    EventTableName = ds.FullName
                };

                XYEvent = (XYName as IName).Open() as IXYEventSource;
                fcInput = XYEvent as IFeatureClass;
            }

            catch (Exception ex)
            {
                strMsg = "0;Failed to create XYEvents from XLS: " + ex.Message + ";" + ex.GetType().ToString();
                Console.WriteLine(strMsg);
                WriteLog(strMsg, true);
                m_AOLicenseInitializer.ShutdownApplication();
                return;
            }



strMsg that's echoed and logged is -
0;Failed to create XYEvents from XLS: Exception from HRESULT: 0x80040213;System.Runtime.InteropServices.COMException;2/12/2013;1:41:13 PM

my debugging WriteLine statements echo the correct file name and that it does exist.

Code runs fine on my PC debugging in VS2010
0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor
Terry,

In your code try testing if the objects WSFac and factoryType are Nothing. This will at least rule out they were not created correctly?

Duncan
0 Kudos
TerryGiles
Frequent Contributor
Thanks for the tip, I've tried that... I removed several debugging console.writeline() statements from the code posted.  These statements seem to indicate they're valid objects -

                //Open XLS as table & make XY layer
                factoryType = Type.GetTypeFromProgID("esriDataSourcesOleDB.ExcelWorkspaceFactory", true);
                Console.WriteLine("type " + factoryType.GetType().ToString() + " " + factoryType.Module.Assembly.ToString());

                System.Object objFact= Activator.CreateInstance(factoryType);

                WSFac = objFact as IWorkspaceFactory;

                //WSFac = (IWorkspaceFactory)Activator.CreateInstance(factoryType);

                Console.WriteLine("factory created " + (WSFac != null).ToString());
0 Kudos
TerryGiles
Frequent Contributor
Got it figured out.  The server has no MS Office components installed.  I installed the AccessDatabaseEngine from MS and now the code is running properly.  All those little things to remember when rebuilding a server 🙂
link to Access 2010 runtime - http://www.microsoft.com/en-us/download/details.aspx?id=13255
0 Kudos
DuncanHornby
MVP Notable Contributor
Terry,

Whilst you were working out it was a server side issue I was testing some code in VBA. It's uploaded for others, just in case they use VB.

Public Sub test()
    Dim path As String
    Let path = "C:\Scratch\graphs.xlsx" ' also works if it is a .xls
    Dim pWSF As IWorkspaceFactory
    Set pWSF = New ExcelWorkspaceFactory
    Dim pWS As IWorkspace
    Set pWS = pWSF.OpenFromFile(path, 0)
    Dim pFWS As IFeatureWorkspace
    Set pFWS = pWS
    Dim pTable As ITable
    Set pTable = pFWS.OpenTable("Sheet1$")
    If pTable Is Nothing Then
        MsgBox "uh oh!"
    Else
        MsgBox "you have a table!"
    End If
End Sub
0 Kudos