Solved

SQL Server msrepl_tran_version inserts fail

Posted on 2010-09-08
13
2,198 Views
Last Modified: 2012-05-10
I have recently set up a replication with updatable subscribers on a couple of remote SQL Server DB's. The column msrepl_tran_version was auto created in all my tables. Inserts fail on some tables, while they go right through on others.

The failures in Management Studio generate...
Cannot insert the value NULL into column 'msrepl_tran_version' table [TABLE NAME]; column does not allow nulls. INSERT fails.

The same query being run through an ASP document produces...
Column name or number of supplied values does not match table definition

I am able to get the inserts to go through if I explicitly list the msrepl_tran_version column and insert (newid()) as the value, but this is not a good solution as I would have to go through thousands of lines of code and add it to each and every query. I'm hoping to find a DB level solution.

The one thing I notice between a couple tables that fail, and the one that works, is that the working one has an identity (auto incrementing) primary key column. Could this have anything to do with the problem on the others? Any other suggestions as to how to fix the issue?
0
Comment
Question by:dale_abrams
  • 7
  • 6
13 Comments
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33630155
when you insert value in table using your ASP page, dont try to write value of AutoIncrement Id.

example, if you have a field MyInc as AutoIncrement Id in a table MyTable, lets assume it has other files like AB, CD, EF

write

INSERT INTO MyTable (AB, CD, EF) VALUES ('','','')

so here dont try to insert value for MyInc.

Is it ok?

0
 
LVL 1

Author Comment

by:dale_abrams
ID: 33630187
I am not writing to any auto incrementing columns on any of the tables. The table that allows inserts has an identity column, but I don't explicitly set a value for it.
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33630217
ok can you please provide code where you are getting error for mismatch columns?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 1

Author Comment

by:dale_abrams
ID: 33630273
Here is one example


INSERT INTO Products
      (Prod_ID, Prod_Name, Prod_Description, Prod_Price, Prod_Category, Prod_Type, Prod_DescriptionLink)
VALUES
      (@Prod_ID,@Prod_Name,@Prod_Description,@Prod_Price,@Prod_Category,@Prod_Type,@Prod_DescriptionLink)
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33630287
What is the type of Prod_ID field?

is it Identity/AutoIncrement Column?
0
 
LVL 1

Author Comment

by:dale_abrams
ID: 33630344
As I mention above, of the tables I tested, the ones that fail do not have identity auto increment fields.

the Prod_ID is an Int PK NOT NULL field.
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33630410
Ok, So according to you your primary key is not set for setting for auto-increment/identity.

Have you tryied debugging your code? any value that you are trying to insert in table (@Prod_Name,@Prod_Description,@Prod_Price,@Prod_Category,@Prod_Type,@Prod_DescriptionLink) may have (') single quote or any other special variable that causing termination of statement and making it as multiple value

like assume your @Prod_DescriptionLink has 'hello's'
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33630464
do you have "msrepl_tran_version" field in your product table?
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33630473
If yes, what is the defination of this field, like int/varchar, null/not null etc..?
0
 
LVL 1

Author Comment

by:dale_abrams
ID: 33631289
The sql code we have has been working for some time. Only now that we have implemented replication does it break. So quotes and things of that nature are not an issue.

I have an auto generated msrepl_tran_version field in all the tables. They get added to all articles when you set up replication. I'm a little unclear on where your going with the questions your asking.

My solution will require changing some database setting as I have already figured out how to fix the problem in my queries by adding the msrepl_tran_version field to them. This is not a solution for me as it would require editing thousands of lines of code. Is this making sense?
0
 
LVL 1

Accepted Solution

by:
dale_abrams earned 0 total points
ID: 33631921
I figured it out. Not all the msrepl_tran_version fields that the replication was supposed to set with the default value of newid() got set. So we just had to set them in SQL Server and now its working.
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33633273
thats is what is asked in my last question:

htttp:#a33630464
do you have "msrepl_tran_version" field in your product table?
0
 
LVL 1

Author Comment

by:dale_abrams
ID: 33637898
There is a big difference between asking whether the field exists after I have stated that it exists in all tables, and finding that the default value did not get set on all fields.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

821 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