Microsoft KB Archive/70675

{|
 * width="100%"|

PRB: When to Use bcp_columns and bcp_colfmt

 * }

Q70675

-

The information in this article applies to:


 * Microsoft SQL Server for OS/2, version 4.2

-

SYMPTOMS
Using the default data formats of the bcp_init function does not work correctly while trying to bulk copy a file that exactly matches the following table column for column:

  dbfcmd (dbproc, &quot;CREATE TABLE %s &quot;, argv[1]); dbcmd (dbproc, &quot;(col1       char(11) NULL,&quot;);   dbcmd  (dbproc, &quot; col2 char(40) NULL,&quot;);

CAUSE
Columns that allow nulls are being used. According to page 219 of the &quot;Microsoft SQL Server Programmer's Reference for C&quot; version 1.11 manual, the default data formats for columns that allow nulls are as follows:

"If a given database column's date is variable length or can contain null values, the operating system file's data column is prefixed by a... 1 byte length value..."

WORKAROUND
Because nulls are being used in the table definition, the 1-byte prefix length must be included in the data file, or the following code fragment, which uses nondefault (that is, no prefix) formatting, can be used instead:

  if ( ! (bcp_columns(dbproc,13) )  ) exit(0); //       file data pre data       term tab //dbproc, col# type len leng term len  col# bcp_colfmt (dbproc, 1  , 0 , 0 , 11 , &quot;\0&quot; , -1 , 1  ); bcp_colfmt (dbproc, 2  , 0 , 0 , 40 , &quot;\0&quot; , -1 , 2  ); Keywords : kbtool

Issue type :

Technology : kbSQLServSearch kbAudDeveloper kbZNotKeyword3 kbSQLServ420OS2