Adding new article to transactional replication gives error at subscriber - sql

I have an updatable transactional replication set with SQL Server 2008. Everything is working fine. I added a new table to the existing publication thru sp_addarticle followed by sp_addsubscription. After that I ran the snapshot agent. Snapshot has been generated only for newly added table. So the new table was successfully replicated to subscriber. I could even able to replicate a newly inserted record into new table to subscriber. But vice versa is not possible. When I insert a record into new table in the subscriber database, I am getting an error
*Msg 515 'Cannot insert the value NULL into column 'msrepl_tran_version',
table Servername.dbo.Tablename'; column does not allow nulls. INSERT fails.'*.
Please help me to resolve this issue.
Many Thanks in advance. Geeta

Is it reproducible error? Is subscriber configured as Immediate Updating? In case of Immediate Updating subscriber the transaction fails whenever publisher (or network) is unavailable.
Check and change, if it does not have it, your table so that ms_repl_tran_version defaulted to GUID:
ALTER TABLE [dbo].[TableName] ADD
CONSTRAINT [DFLT_GUID_msrepl] DEFAULT (newid()) FOR
[msrepl_tran_version]

Related

Append existing data to table with identity

SQL Server 2014: I am importing a table that is living in an old SQL Server to a new server. What I did was download the table to MS Access, then uploaded it to the new server (different environments).
The problem is that on upload, my primary key and auto increment are dropped. PK was easy to fix, and I was able to add a new identity column, but now I cannot append to the identity column as an error saying IDENTITY_INSERT is ON. So I turned it off, but still getting the same error.
Any ideas work a workaround?
Reading the documentation for INDENTITY_INSERT:
At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, SQL Server returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.
If you already tried turning it off for the other table, you might be in a transaction - try issuing a COMMIT.

SQL Server Replication - Duplicate subscription agents?

I am new to SQL Server replication, and pushed some changes out to an existing replicated environment. It is SQL Server 2005 SP3, with Transactional replication.
I created a new table, added columns to an existing table, and added some SPs. I did all of this on the publisher database.
I created a new snapshot and reinitialized the subscriptions. The new table and new columns were replicated to the new server, and data was synchronized successfully, but just 1 time.
Immediately after, the replication monitor is reporting an error. On the Distributor to Subscriber History tab, I get a message that the "Subquery returned more than 1 value". The Command Attempted is...
delete from MSsubscription_articlecolumns
where artid=89 and
agent_id = (
select id from MSsubscription_agents
where update_mode > 0 and
UPPER(publisher) = UPPER('xxxx') and
publisher_db = N'xxxx' and
publication = N'xxxxx'
) end
Why would there be duplicate subscription agents? How do I fix this? Thanks for all help.
I was able to resolve the issue by manually editing the data in the MSsubscription_agents table. There were 2 records with the same publisher, db and publication names. Instead of deleting one of the records, I changed the update_mode on the older record to be 0, which filtered it out of the problem statement in original question. The replication process was then able to get past that statement and run correctly. Thanks.

Replication - Explicit value must be specified for identity column in table

I'm using Merge Replication. The Identity range management is AUTOMATIC
I HAVE A TRIGGER ON COMPANIES TABLE WHICH INSERTS ROWS IN SERIALNUMBERSCHEME TABLE which has documentID as identity column
While synchronizing I'm getting below error
A row insert at 'SERVER\MUMBAI.PROD_SUB' could not be propagated to 'SERVER\NEWYORK.PROD'. This failure can be caused by a constraint violation. Explicit value must be specified for identity column in table 'SerialNumberScheme' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.
Data is inserted properly at subscriber but not replicated at publisher
Any solution/suggesstion?
Sounds like your trigger gets fired when the replication agent applies the updates. Normally the trigger should run only at the publisher (or more precisely, at the site which inserts the original data). Then replication will replicate the effect of the trigger. I think that all you need is to mark the trigger as NOT FOR REPLICATION.
See Controlling Constraints, Identities, and Triggers with NOT FOR REPLICATION.

Trigger in subscriber is getting deleted when replication is created

I have a table A in publisher database and there is trigger which inserts data into table B when an entry happens in table A. I have the same configuration in subscriber database,
that is Table A, Table B and the trigger. I have done transactional replication for both the DB and after the establishing the replication, trigger in subscriber database is deleted. Please give me the reason why the trigger in subscriber is deleted when the replication is created.
Is your trigger created with the "NOT FOR REPLICATION" option?
Rob

SQL Server Replication - Adding a new stored procedure - How to get it to replicate?

I have a SQL Server 2005 Database which uses merge replication.
I have added four new stored procedures on the publisher end, but they haven't replicated.
The publication property "Subscription Options" - "Replicate schema changes" is set to True.
How can I get easily get these tables replicated without having to send new snapshots to all of the subscribers?
I found this bit of code, perhaps it will help.
create table table2(pk int not null primary key, charcol char(20))
GO
sp_addarticle 'paul','table2','table2'
GO
sp_refreshsubscriptions 'paul'
GO
sp_addsubscription 'paul','table2',##servername,'paulsub'
GO
Adding the article and then running the snapshot agent seems to reinit the entire publication.