Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem:

1. Have two instances of SQL Server running on same box
2. Have data of geo/geom spatial type on one instance.
3. Have created a target table of the same types on second instance.
4. Have EXECUTE's "sp_addLinkedServer" on both instances so each can see each other's tables.
5. Can successfully make a SELECT query of the geo spatial data from one to the other using OPENQUERY
6. As prescribed by excellent sqlserver2k8 help, SET IDENTITY_INSERT of the target table (local) to ON.
7. Have run select in the form:

SQL
INSERT INTO [local].[gstable_01].[dbo].[target]
   SELECT [id],[GeomCol1],[GeomCol2] FROM OPENQUERY([remote], 'SELECT [id],[GeomCol1],[GeomCol2] FROM [remote].[gstable_02].[dbo].[origin]')


8. But all I get is this error

Msg 8101, Level 16, State 1, Line 1

An explicit value for the identity column in table 'gstable_01.dbo.target' can only be specified when a column list is used and IDENTITY_INSERT is ON.


As I stated in the title of this Question, both of these keywords, OPENQUERY and IDENTITY_INSERT, are to be found nowhere in any posts in Q&A. As far as all the other stuff regarding either of these words seperately is concerned, I've read the posts and some of those answers are even defective as is. So don't bother to search there for something to reiterate here.

Thanks in advance.
Posted
Updated 22-Oct-12 10:05am
v3

1 solution

The error message speaks for itself. The issue is that you have the ID column configured as IDENTTY, which is correct, but that will cause you an error if you try to insert a specific ID into that column as per your query. That doesn't mean your query is bad because synchronization in these instances is what you probably want.
The solution is to preface your INSERT statement with a
SQL
SET IDENTITY_INSERT [local].[gstable_01].[dbo].[target] OFF;
and then turn it back on when you are done:
SQL
SET IDENTITY_INSERT [local].[gstable_01].[dbo].[target] ON;
 
Share this answer
 
Comments
RedDk 19-Oct-12 18:06pm    
Well,

This idea still doesn't work.

Has anybody got a snippet of code that has both OPENQUERY and IDENTIY_INSERT in it, is taking data from one spatial data table of one instance and inserting it into a fresh datatable on another instance that has the two tables linked only by the fact that they're running simultaneously on the same computer under different instance name and are actually LINKED SERVERS?
RedDk 19-Oct-12 18:32pm    
Marcus,

Here's something to add to this that you'll enjoy hearing. I occured to me that one of the errors I was getting was quite odd. It was basically saying that during a selective filter of the return types, qualifying what columns to return by exclusion, that the "one-to-one" wasn't matching the type I was asking for. IE: the complaint was about geometry but I was specifying int. So I boiled down the table to particular columns; by your suggestion, I removed the IDENTITY column itself and asked for just geometry. And the return INSERT went into an indexless two column table in the local.

So, that's good enough for me for what I wanted to do. I'll just go and reindex the brand new local data.

So, although I'm not sure how to do this to retain that index that is flubbled, your solution is good enough.

[EDIT] pseudoflycode

SELECT IDENTITY (int, 1, 1) AS [Id] INTO [local].[dbo].[gstable_mod].[target] FROM [local].[dbo].[gstable_mod2].[target2]

[END EDIT]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900