SQL Server msrepl_tran_version inserts fail

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?
LVL 1
dale_abramsAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
dale_abramsConnect With a Mentor Author Commented:
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
 
Mohit VijayCommented:
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
 
dale_abramsAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Mohit VijayCommented:
ok can you please provide code where you are getting error for mismatch columns?
0
 
dale_abramsAuthor Commented:
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
 
Mohit VijayCommented:
What is the type of Prod_ID field?

is it Identity/AutoIncrement Column?
0
 
dale_abramsAuthor Commented:
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
 
Mohit VijayCommented:
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
 
Mohit VijayCommented:
do you have "msrepl_tran_version" field in your product table?
0
 
Mohit VijayCommented:
If yes, what is the defination of this field, like int/varchar, null/not null etc..?
0
 
dale_abramsAuthor Commented:
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
 
Mohit VijayCommented:
thats is what is asked in my last question:

htttp:#a33630464
do you have "msrepl_tran_version" field in your product table?
0
 
dale_abramsAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.