Skip to Content.
Sympa Menu

freetds - [freetds] Freebcp copy into ms sql server fails if field is null

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Thomas A. Lowery" <tlowery AT rparts.us>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Freebcp copy into ms sql server fails if field is null
  • Date: Tue, 16 Nov 2004 15:27:38 -0500

My attempts to use freebcp to populate a database table results in
# Msg 20073, Level 2
# Attempt to bulk-copy a NULL value into Server column which does not accept
NULL values.

There appears to be problem if any of the columns are null.

Here's a script to demo the problem.

#!/bin/bash

USER=myuser
PASS=mypass
SERVER=server
do_sqsh()
{
sqsh -e -b -U $USER -P $PASS -D db -S $SERVER -C "$*";
}

do_sqsh 'drop table dbo.test_me'
do_sqsh 'create table dbo.test_me (i integer not null primary key, c
varchar(10) null)'
do_sqsh "insert into dbo.test_me values (3,'string')"
do_sqsh "insert into dbo.test_me values (1,'string2')"
do_sqsh 'insert into dbo.test_me values (2,null)'
do_sqsh 'select * from dbo.test_me'

freebcp db.dbo.test_me out test_me.txt -S $SERVER -U $USER -P $PASS -c
do_sqsh 'truncate table dbo.test_me'
freebcp db.dbo.test_me in test_me.txt -S $SERVER -U $USER -P $PASS -c

exit;

# freebcp -v
# freebcp version $Id: freebcp.c,v 1.17 2003/01/26 10:27:35 freddy77 Exp $

# [3] server.db.1> drop table dbo.test_me
# [3] server.db.1> create table dbo.test_me (i integer not null primary key,
c varchar(10) null)
# [3] server.db.1> insert into dbo.test_me values (3,'string')
# [3] server.db.1> insert into dbo.test_me values (1,'string2')
# [3] server.db.1> insert into dbo.test_me values (2,null)
# [3] server.db.1> select * from dbo.test_me
# i c
# ----------- ----------
# 1 string2
# 2 NULL
# 3 string
#
# (3 rows affected)
#
# Starting copy...
#
# firstrow = 0 row_of_query = 3 rows written 3
# 3 rows copied.
# [3] server.db.1> truncate table dbo.test_me
#
# Starting copy...
#
# Msg 20073, Level 2
# Attempt to bulk-copy a NULL value into Server column which does not accept
NULL values.
#
# bcp copy in failed




Archive powered by MHonArc 2.6.24.

Top of Page