I thought there was a page explaining this somewhere out there on the Internet, but I can't find it anymore. So here's what I re-discovered.
When you try to insert the rows from a DataTable and the data in one of the columns of one of the rows is too big to fit into the destination column in the database, you get a SqlException with this error message: "Received an invalid column length from the bcp client for colid N." (Where "N" is a number.) It doesn't tell you which row, and it's a pain to figure out what column to look at.
To determine what column it is referring to, you first need to get a listing of all columns in the table, listed in the order as they have been defined in the database. Next, you remove any columns in the list that are not represented in SqlBulkCopy.ColumnMappings (the order of the column mappings is irrelevant). The list that remains is what "colid" is referring to, with the first column corresponding to colid "1". You can now tell what column the error message is talking about (even though you still don't know what row).
If you want to delve into private variables, SqlBulkCopy has a private variable named "_currentRow" that appears to have a reference to the DataRow that was being worked on when the Exception was raised. (No, the SqlRowsCopied event cannot help you here.) Other than that, there's nothing else hidden inside SqlBulkCopy (anywhere) that is useful to reliably indicate the name of the column with the problem.
When you try to insert the rows from a DataTable and the data in one of the columns of one of the rows is too big to fit into the destination column in the database, you get a SqlException with this error message: "Received an invalid column length from the bcp client for colid N." (Where "N" is a number.) It doesn't tell you which row, and it's a pain to figure out what column to look at.
To determine what column it is referring to, you first need to get a listing of all columns in the table, listed in the order as they have been defined in the database. Next, you remove any columns in the list that are not represented in SqlBulkCopy.ColumnMappings (the order of the column mappings is irrelevant). The list that remains is what "colid" is referring to, with the first column corresponding to colid "1". You can now tell what column the error message is talking about (even though you still don't know what row).
If you want to delve into private variables, SqlBulkCopy has a private variable named "_currentRow" that appears to have a reference to the DataRow that was being worked on when the Exception was raised. (No, the SqlRowsCopied event cannot help you here.) Other than that, there's nothing else hidden inside SqlBulkCopy (anywhere) that is useful to reliably indicate the name of the column with the problem.
Comments