Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Unable to insert into identity column with linked servers

Posted on 2000-03-01
4
Medium Priority
?
632 Views
Last Modified: 2008-02-26
Hi,
If I'm inserting records and I want to specify a value for an identity column on a local table I do this and everything works fine:
set identity_insert <table> on
insert <table> (f1 , f2) select 1 , 'blah'

But when I try to do the same thing from a linked server I encounter an error. I execute this SQL after setting up the linked server:
set identity_insert <server>.<database>.<owner>.<table> on

error message I encounter:
Server: Msg 8103, Level 16, State 1, Line 1
Table '<server>.<database>.<owner>.<table>' does not exist or cannot be opened for SET operation.

Can you not execute a SET command on a linked server? If not how can I explicitly insert values into the identity columns of linked tables?

Thanks!
Andrew
0
Comment
Question by:Andrew_Wiegand
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 4

Expert Comment

by:Gustavo Perez Buenrostro
ID: 2573170
Andrew_Wiegand,

You cannot execute SET operation on a linked server. See "SET IDENTITY_INSERT (T-SQL)" topic in BOL.

Why don't you use a remote stored procedure?

PD: More info is needed for better advice.
0
 

Author Comment

by:Andrew_Wiegand
ID: 2573400
SET IDENTITY_INSERT topic in BOL does not offer any information regarding executing the command with linked servers.  Remote Stored Procedures are a legacy feature of SQL Server 6.5 and I would rather not use them in 7.0.  Let me know what information you need and I'd be happy to provide it.  Like I mentioned above my problem is this:

How do I insert explicit values into the identity column of a table on another server using linked servers?

Perhaps this is not allowed?

Andrew
0
 
LVL 6

Expert Comment

by:Jon_Raymond
ID: 2575306
Just an idea:  Could you create a trigger on the table to run set identity_insert when an identity error occurs.  You might also need another flag field to determine if the insert is supposed to do this.
0
 
LVL 4

Accepted Solution

by:
wqw earned 900 total points
ID: 2575827
the other nasty error you might get when trying to set indetity_insert on linked server table is
Server: Msg 117, Level 15, State 1, Line 7
The object name '<server>.<db>.<owner>.' contains more than the maximum number of prefixes. The maximum is 2.

this is when elevating to distrbuted transaction.

well, i managed to insert values in a table on a linked server but don't ask me how. it's ugly. ok, here it is:

select * from openquery(boraweb,'select top 0 * from test1 set identity_insert test1 on insert test1 (id,c2)
values (25,''y0'')')

i told you it is ugly :-))

</wqw>
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question