all groups > sql server replication > july 2003 >
You're in the

sql server replication

group:

Trans Replication - Identity Insert Error


Re: Trans Replication - Identity Insert Error Richard Ding
7/30/2003 3:19:49 PM
sql server replication:
[quoted text, click to view]

You can modify the sp_MSins_tablename stored procedure, adding something
like this:

create procedure sp_MSins_tablename as
if not exists (select * from tablename where col1 = @c1 and col2 = @c2 and
....... ) -- include all PK keys here
begin
set identity_insert tablename on
insert into tablename (col1, col2....) values (@c1, @c2...)
end

[quoted text, click to view]

To tell if the table was created as "not for replication", right click on
table and choose "All Tasks" and then generate SQL script. Click on
"Preview" button and you'll be able to see its schema script.

How can I
[quoted text, click to view]

I usually run schema script with "not for replicaton" on the subscriber
BEFORE I create the table. But you obviously wan to avoid doing this. The
hacking way of making it to look like "not for rep" is to update the colstat
value from 1 to 9 in syscolumn table. But I 've never tested on the real
replication. You risk fixing unwanted problems on your own. I suggest
breaking the replicatin, renaming the existing table, creating new table
with "not for replicaton" , copying data from old table and resetting up the
replication.

HTH.

Richard

Trans Replication - Identity Insert Error Ricky_Singh
7/30/2003 4:34:50 PM

Hi,

I recently started doing transaction replication for our production
server. Distribution Agent is scheduled to run at a certian time
every night.

Now, I am getting an error, which is:

"
Cannot insert explicit value for identity column in table 'tablename'
when IDENTITY_INSERT is set to OFF.
"
The error occurs when the Insert/Update stored procedure is executed at
the subscriber. Two possible solutions I need suggestions on :

-- Set the IDENTITY_INSERT to ON before running Distribution Agent. If
yes, how to do that.
OR
-- I am not sure if the identity columns were created using the NOT FOR
REPLICATION option. How can I now approach this situation? How can I
mark identity columns - "Not For Replication" ?
I have seen a hack solution using the syscolumns table! Has this worked
for anyone? if yes, can u please some shed light on it!!



Thanks Guys!

--
Re: Trans Replication - Identity Insert Error Ricky_Singh
7/30/2003 9:25:11 PM

Thanks Richard for your time.
So my options are either add the bit to the stored procedures or Alter
the tables for which the identity column doesnt have the " NOT FOR
REPLICATION" clause.
Is that right!!



Originally posted by Richard Ding
[quoted text, click to view]
Richard

--
AddThis Social Bookmark Button