[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Unable to insert into identity column with linked servers

Posted on 2000-03-01
4
Medium Priority
?
641 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
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

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

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 …
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

830 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