Error when BCP into uniqueidentifier column

  • Hi,

    I have a text file myfile.dat that looks something like this:

    id global_id                                                             code date
    1 DE2EC0E1-3B8F-40E5-9D68-630E40E2C22C 01 2016-04-01
    2 F29BB843-764C-463B-9EF4-3EB5998531EE   02 2016-05-01
    3 A4E02989-DA4F-4ACA-939F-0B871566299D  03 2016-06-01

    and a third party tool is trying to bcp its data to an sql table like this:

    create table sql_table (
    [id] INT NOT NULL,
    [global_id] uniqueidentifier NOT NULL,
    CHAR(2) NOT NULL,
    [date] date NOT NULL
    )

    here is an error:

    EXCEPTION TYPE:System.Management.Automation.MethodInvocationException
    DESCRIPTION:
    * Exception calling "WriteToServer" with"1" argument(s): "The given value of type String from the data
      source cannot be converted to typeuniqueidentifier of the specified target column."

    it does not happen if all the columns in sql_table are, say, VARCHAR(100), and bcp works fine then

    Is there anything that can be done w/o changing all those fields to be varchars?

    Thank you

  • I would try and do one of those loads onto a varchar(100) and then do a select convert(uniqueidentifier, varcharcolumn) and see if any fails.

    If the test above does not fail, and the "bcp" fails it may be an issue on how the BCP is being executed.

    And regarding bcp --- is it using the bcp.exe supplied with sql server or is it a custom application that is using a bulkcopy method?

  • frederico_fonseca - Wednesday, March 15, 2017 12:52 PM

    I would try and do one of those loads onto a varchar(100) and then do a select convert(uniqueidentifier, varcharcolumn) and see if any fails.

    If the test above does not fail, and the "bcp" fails it may be an issue on how the BCP is being executed.

    And regarding bcp --- is it using the bcp.exe supplied with sql server or is it a custom application that is using a bulkcopy method?

    Thank you Frederico, that works fine but I do not have control and/or knowledge of what and how it's being done on their end....

    so far it looks like it's using bcp.exe which does have some issue with uniqueidentifier type (similar problem with BIT too)

    after the receiving side tweaked their code to not require those uniqueidentifiers it worked ok of course
    Thanks again.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply