Skip to main content

Posts

Showing posts with the label c#

SqlBulkCopy and the "colid" error

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 ...

Filling out a PDF form with iTextSharp

I needed to make an aspx page that would allow me to pull a PDF from disk, fill out fields in it, then stream the completed PDF to a browser. After searching around, I found that the consensus seems to be that iTextSharp is the way to go in C#. I grabbed version 4.1.2. While the iText API docs are useful, it's hard to start out with that. I found that this example proved the most informative and useful of those that popped up on Google. However, even with that, I found that only the source code really answered all of my questions. Extra things I found noteworthy: All of the PdfReader constructors ultimately use the RandomAccessFileOrArray object to access the source PDF data. The PdfReader(RandomAccessFileOrArray...) constructor results in a partial read ( ReadPdfPartial() ), whereas all the others read & parse the entire PDF ( ReadPdf() ) during construction. It appears, from this post , that the former uses less RAM, but the other constructors result in faster performanc...