cancel
Showing results for 
Search instead for 
Did you mean: 

AseBulkCopy.WriteToServer fails when target has an identity column

0 Kudos

My source has 2 columns (Viz: ForeName and SurName) and Destination has 3 columns out of which one is identity column (viz Id(smallint identity), Forename and Surname ).

The Mapping for Id column is null (i.e. no mapping is done)

using (AseBulkCopy blk = new AseBulkCopy(connectionString))
 { //set the timeout as the default is 30s 
       blk.BulkCopyTimeout = 30; 
      blk.DestinationTableName = "Employee";
      blk.ColumnMappings.Clear();
      //Mapping Source and target ordinals
      blk.ColumnMappings.Add(new AseBulkCopyColumnMapping(0,1));
      blk.ColumnMappings.Add(new AseBulkCopyColumnMapping(1,2));
      blk.WriteToServer(dataSource);
      blk.Close();
}

AseBulkCopy.WriteToServer(dataSource) Throws an exception Sybase.Data.AseClient.AseException: Bulk insert failed. Null value is not allowed in not null column.

bob_gallo58
Participant
0 Kudos

SAP Sybase Mainframe Connect is not the correct tag for this questions.
The correct Tag should be SAP Adaptive Server Enterprise.
This will get the correct audience to take a look at your question
Thank you

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member89972
Active Contributor

This is from DBA perspective more familiarity with ASE utility bcp -

bcp - in has two options to handle identity columns while loading data.

-E to take data from input file. So identity column must be included in the data

-g <Identity start value> - Idenity column not included in the data

In the C# code do you have any setting to simulate the second option above and give it a start value of 1 or whatever suits your requirement.?

HTH

Avinash

dawn_kim
Contributor
0 Kudos

Hi,

I remember this exact problem years ago. This was CR 678477 Using EnableBulkLoad=0 with identity column results in error. This was fixed in 15.7 ESD#5 and higher.

Are you adding enablebulkload=1 to your connection string?

I also remember an issue with identity column that was corrupted that caused this same issue, the identity value was changed and the ASE didn't map the change correctly, some ASE bug if I remember right.

Thanks,
Dawn Kim