Click here to Skip to main content
13,503,383 members
Rate this:
Please Sign up or sign in to vote.
See more:

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:

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 '' 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 19-Oct-12 11:17am
Updated 22-Oct-12 10:05am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
SET IDENTITY_INSERT [local].[gstable_01].[dbo].[target] OFF;
and then turn it back on when you are done:
SET IDENTITY_INSERT [local].[gstable_01].[dbo].[target] ON;
RedDK 19-Oct-12 18:06pm

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

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]


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180417.1 | Last Updated 22 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100