Link to home
Start Free TrialLog in
Avatar of dale_abrams

asked on

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?
Avatar of Mohit Vijay
Mohit Vijay
Flag of India image

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


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

so here dont try to insert value for MyInc.

Is it ok?

Avatar of dale_abrams


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.
ok can you please provide code where you are getting error for mismatch columns?
Here is one example

      (Prod_ID, Prod_Name, Prod_Description, Prod_Price, Prod_Category, Prod_Type, Prod_DescriptionLink)
What is the type of Prod_ID field?

is it Identity/AutoIncrement Column?
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.
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'
do you have "msrepl_tran_version" field in your product table?
If yes, what is the defination of this field, like int/varchar, null/not null etc..?
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?
Avatar of dale_abrams

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thats is what is asked in my last question:

do you have "msrepl_tran_version" field in your product table?
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.