SQL Server – BCP Error – “String Truncation”

Background

Trying to Bulk copy data but running into error.

Error

Error Image

stringdatarighttruncation.20190108.0552pm

Error Text


SQLState = 22001, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]String data, right truncation
1000 rows sent to SQL Server. Total sent: 1591000
SQLState = 22001, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]String data, right truncation

1591585 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 347468 Average : (4580.52 rows per sec.)

Troubleshooting

We copied the data over using character mode and it is possible carriage return our default line terminator is naturally occurring.

Remediation

Change from character mode (-c) to native mode ( -n)

Next Error

Image

unexpectedEOFEncounteredInBCPDatafile.20190108.0604PM.PNG

Textual


1000 rows sent to SQL Server. Total sent: 3198000
1000 rows sent to SQL Server. Total sent: 3199000
1000 rows sent to SQL Server. Total sent: 3200000
1000 rows sent to SQL Server. Total sent: 3201000
1000 rows sent to SQL Server. Total sent: 3202000
1000 rows sent to SQL Server. Total sent: 3203000
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]
Unexpected EOF encountered in BCP data-file

 

References

  1. Github
    • Microsoft
      • msphpsql
        • PDOException: String data, right truncation when insert a long string #169
          Link

SQL Server – BulkCopy ( BCP ) – Which data file?

Background

Using BCP, we are churning though quite a bit of files.

Unfortunately, the DOS batch file that I quickly stitched together missed an importantly functionality.

And, that functionality is to log the current file being processed.

Diagnostic

Microsoft

Resource Monitor

I am a big fan of Microsoft’s Resource Monitor.

Let us use it.

Preparation

We remote connect to the source computer and launched task Manager; from Task Manager accessed Resource Monitor.

Resource Monitor – Tab – Memory

Image

ResourceMonitor_Tab_CPU_ProcessesAndAssociatedHandles_20180706_0850AM.png

Explanation
  1. When we filter on the bcp.exe process, we see our data file as one of the files mentioned in the “Associated Handles” tab

 

Resource Monitor – Tab – Memory

Image

ResourceMonitor_Tab_Memory_20180706_0852AM.png

Explanation
  1. The BCP process is using about 14 MB

 

Resource Monitor – Tab – Disk

Image

ResourceMonitor_Tab_Disk_20180706_0907AM.png

Explanation
  1. sqlserver,exe is mentioned
  2. But, not our bcp.exe file

 

Summary

To get a reliable insight into which files are being accessed, please consider Microsoft’s own Resource Monitor; specifically the CPU tab.