Spatial view - ArcCatalog-OID Error

5253
9
06-07-2016 09:32 AM
naveenmandava1
New Contributor II

I have created a Spatial View in SQL Server management studio. After I create the view, I tried to open the table in ArcCatalog and I get this error. Any help would be appreciated.

"There was an error initializing the table window. If the table does not have an oid field, ensure that a temp file can be created in the TEMP directory.

Thanks,

Naveen  Mandava.

9 Replies
NaomiBegg2
Occasional Contributor III

I am finding I get this error too. 

I am able to view and manipulate the data in ArcMap 10.3 but I am finding that it causes problems when I am trying to automate an arcpy.CopyRows_management script.

More info on my problem: arcgis desktop - Loading Data Error from MSSQL View? - Geographic Information Systems Stack Exchange  

I have the extended error message: 

Loading table data: There was an error initializing the table window. If the table does not have an oid field, ensure that a tempory file can be created in the TEMP directory, so the table can be copied locally. Each grid size must be at least three times larger than the preceding grid size. The workspace is not connected. Item not found in this collection.

Anish_Adhikari
Occasional Contributor

I am also getting the exact same error. Same as Naomi. For me it shows up fine when I preview geography in arccatalog and get this error when I preview table. The strange thing is it only gives me this error occasionally. It also sometimes goes away when I refresh the database connection.  For now, I do not have any problems when I import the view in ArcMap and Publish it as a map service. I am however worried that down the road it may cause issues with our GIS application that references the data. 

0 Kudos
StephanieBlazey
New Contributor III

I am getting the same error as Naomi's screenshot too.  Same as Anish says, the geometry looks fine in ArcCatalog and I get the error when previewing the table.  When I add data to ArcMap it asks me to choose a unique identifier field (and OBJECTID is definitely there).  Are we missing a step where we can set which field is the unique identifier when we create the view?

0 Kudos
StephanieBlazey
New Contributor III

I think I understand the problem here -- I'm creating a spatial view with a 1-M relationship, so my ObjectID field won't be unique anymore.  I need to figure out a way to create a new unique ID field in the spatial view.

0 Kudos
StephanieBlazey
New Contributor III

I'll start off saying I'm not sure how big of an issue it is to create a spatial view and not have a unique identifier, but it seems like something that might cause issues down the road so I want to avoid it.

Ok I figured this out! 

(EDIT -- NEVER MIND!!  The query layer (as illustrated below) works in ArcMap, however, you can't publish a "complex" query layer (e.g. one that has joins or a where clause).  You CAN publish a "simple" query layer (no joins, no where clause).  But in my case I needed those joins and where clauses and I need to publish it so this doesn't help.  Back to spatial views with no unique identifier!)

Instead I created a Query Layer in ArcMap. I'm using 10.3.1, and followed these steps:

1. In ArcMap, Click File > Add Data > Add Query Layer.

2. It will ask you to provide the database connection. (see image below)

3. Type in a name for your new layer.

4. Create a query.  I used the same SQL that I would have used to create the spatial view (which I copied from SQL server management studio).

New Query Layer

This gives you a new layer in your MXD that does exactly what your spatial view would have done, plus it adds an "ESRI_OID" field that has a true unique identifier.

You can save and publish the MXD as usual.  You can even save the layer as a .lyr file to easily use in other documents.

So the downside is that you don't have a spatial view in your geodatabase to easily use, but since you can save .lyr files you don't have to rewrite the SQL every time you use the same data -- or even similar data, as you can edit the query in ArcMap whenever you need!

StephanieBlazey
New Contributor III

NEVER MIND! 

You can't publish an MXD with a "complex" query layer, e.g. it can't have a join or a where clause. So this doesn't help at all.

Onwards with spatial views with no unique ID!

StephanieBlazey
New Contributor III

Ok so we finally got this sorted out.  You can add an ObjectID field when you create the spatial view definition!

add something along the lines of:

cast(ROW_NUMBER() OVER (ORDER BY {FieldOfChoice}) AS int) AS OBJECTID

how to add objectID to a view.

MikeDolbow
New Contributor III

Awesome! Just the answer I needed, thanks for posting this!!!

0 Kudos
DaleSmith
New Contributor

Exactly what I needed. Thank you Stephanie!

0 Kudos