2

I'm trying to load features into ArcSDE without using ArcObjects, and using SQL from my .NET Application instead.

I have followed the answers given in this question: Is it possible to load features into ArcSDE without using ArcObjects?

The Only problem, is that in the insert SQL Statement, I have to give the objectID, like this:

INSERT INTO [mydatabase].[dbo].[DATAPTS]
           ([OBJECTID],[tor]
           ,[value]
           ,[SHAPE])
     VALUES
           (1,dateadd(hour, 11, dateadd(dayofyear, 62 - 1, dateadd(year, 2013 - 1900, 0)))
           ,0.23654
           ,geometry::STGeomFromText('POINT (30000 198572)', 32643))
GO

Is this the best way to give the object Id?
Or is there any way to get SQL Server to auto increment this field?

(The second looks impossible, because the Featureclass created by ArcGIS in the SDE, has int as the OBJECTID, and you can't Add identity to an existing column)

2

Get the max ObjectID value from the table first, add one to that and use the result in your insert statement.

values ((select MAX(OBJECTID) from [dbo].[DATAPTS]) + 1 , ...

DG

  • That is exactly what I am doing now; But I wonder if there is a better way to do this. – Devdatta Tengshe May 14 '13 at 6:43
  • As you stated, the feature table does not auto increment the ObjectID field so you have to manually set a unique value when you insert in SQL. The MAX aggregate is a very fast SQL operation especially since OBJECTID is a primary indexed key. I think in ArcGIS Desktop, the ArcObjects code that adds records to a feature class is doing a similar operation. I would think the SQL MAX aggregate would be faster than ArcObjects at determining the max value. – DLG May 14 '13 at 7:48
  • If you use your database in a multi user environment then this way may cause an "unique constraint error on ObjectId column" when two concurrent transaction runs and want to insert a record into feature class table.because two concurrent transaction get same max ObjectId,and every one can insert it sooner,the other fail to insert same ObjectId into this column.I had this problem some months ago.ArcObject uses some "get_Ids" and "return_ids" stored procedures which has been built in SDE repository(in SQL Server geodabases) – Reza Dec 22 '16 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.