Skip to Content
0
Aug 27, 2018 at 06:51 AM

AseBulkCopy.WriteToServer fails when target has an identity column

184 Views Last edit Aug 29, 2018 at 12:24 PM 4 rev

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.