Click here to Skip to main content
11,647,037 members (74,469 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: T-SQL
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:

   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 19-Oct-12 11:17am
RedDk11.9K
Edited 22-Oct-12 10:05am
v3

1 solution

Rate this: bad
good
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;
  Permalink  
Comments
RedDK at 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 at 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)

  Print Answers RSS
0 jyo.net 510
1 Sergey Alexandrovich Kryukov 423
2 OriginalGriff 398
3 CPallini 339
4 DamithSL 300
0 OriginalGriff 1,253
1 jyo.net 994
2 DamithSL 896
3 Sergey Alexandrovich Kryukov 833
4 CPallini 720


Advertise | Privacy | Mobile
Web01 | 2.8.150804.2 | Last Updated 22 Oct 2012
Copyright © CodeProject, 1999-2015
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