Unix Technical Forum

SQLDMO.Bulkcopy diagnostics on failed load

This is a discussion on SQLDMO.Bulkcopy diagnostics on failed load within the SQL Server forums, part of the Microsoft SQL Server category; --> I use SQLDMO.Bulkcopy in an VB6 (have to) program to load data from a plain text file into a ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:45 PM
Nils
 
Posts: n/a
Default SQLDMO.Bulkcopy diagnostics on failed load

I use SQLDMO.Bulkcopy in an VB6 (have to) program to load data from a
plain text file into a SQL Server 2000.
One of the target columns is NOT NULL but it happens that I receive a
missing value for that column in the source file. BulkCopy then has an
ODBC error raised that complains about the violated NOT NULL
constraint. The Bulkcopy error file however is empty. Is there a way
to figure out in which row of the source file the error occured ?
Maybe a call to some ODBC diagnostics method to receive further
information ? I'd like to avoid the obvious solution to drop the
constraint and then query the loaded data for NULL values.


Thanks
Nils
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:45 PM
Erland Sommarskog
 
Posts: n/a
Default Re: SQLDMO.Bulkcopy diagnostics on failed load

Nils (dev@nils-dehn.de) writes:
> I use SQLDMO.Bulkcopy in an VB6 (have to) program to load data from a
> plain text file into a SQL Server 2000.
> One of the target columns is NOT NULL but it happens that I receive a
> missing value for that column in the source file. BulkCopy then has an
> ODBC error raised that complains about the violated NOT NULL
> constraint. The Bulkcopy error file however is empty. Is there a way
> to figure out in which row of the source file the error occured ?
> Maybe a call to some ODBC diagnostics method to receive further
> information ? I'd like to avoid the obvious solution to drop the
> constraint and then query the loaded data for NULL values.


The common approach it to use a staging table and move on from there,
but that is of course an extra that you may want to avoid if this
happens rarely.

It seems that NOT NULL errors are not logged in the error file. Furthermore,
the appear to cause bulk load to terminate directly. (I tried command-
line which uses ODBC as well.) You could set the batchsize to 1,
in that case the bulkload will load all record up to the erroneous
record. (But beware that a batchsize of 1 can severely affect performacne
for large files. If you are loading into a new table without indexes,
this can also lead to a disk explosion.)

If this is a one-off, try using BULK INSERT instead. When I tested, I
got a clear error message which said:
"The bulk load failed. Unexpected NULL value in data file row 3, column 1.
The destination column (a) is defined as NOT NULL."
Furthermore, when I used BATCHSIZE = 1, all rows but the bad one was
loaded. I should hasted to add that I did all these tests with SQL 2005,
but I would expect SQL 2000 to be the same.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:45 PM
scoots987
 
Posts: n/a
Default Re: SQLDMO.Bulkcopy diagnostics on failed load

On Dec 9, 5:31 pm, Erland Sommarskog <esq...@sommarskog.se> wrote:
> Nils (d...@nils-dehn.de) writes:
> > I use SQLDMO.Bulkcopy in an VB6 (have to) program to load data from a
> > plain text file into a SQL Server 2000.
> > One of the target columns is NOT NULL but it happens that I receive a
> > missing value for that column in the source file. BulkCopy then has an
> > ODBC error raised that complains about the violated NOT NULL
> > constraint. The Bulkcopy error file however is empty. Is there a way
> > to figure out in which row of the source file the error occured ?
> > Maybe a call to some ODBC diagnostics method to receive further
> > information ? I'd like to avoid the obvious solution to drop the
> > constraint and then query the loaded data for NULL values.

>
> The common approach it to use a staging table and move on from there,
> but that is of course an extra that you may want to avoid if this
> happens rarely.
>
> It seems that NOT NULL errors are not logged in the error file. Furthermore,
> the appear to cause bulk load to terminate directly. (I tried command-
> line which uses ODBC as well.) You could set the batchsize to 1,
> in that case the bulkload will load all record up to the erroneous
> record. (But beware that a batchsize of 1 can severely affect performacne
> for large files. If you are loading into a new table without indexes,
> this can also lead to a disk explosion.)
>
> If this is a one-off, try using BULK INSERT instead. When I tested, I
> got a clear error message which said:
> "The bulk load failed. Unexpected NULL value in data file row 3, column 1.
> The destination column (a) is defined as NOT NULL."
> Furthermore, when I used BATCHSIZE = 1, all rows but the bad one was
> loaded. I should hasted to add that I did all these tests with SQL 2005,
> but I would expect SQL 2000 to be the same.
>
> --
> Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se
>
> Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
> Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


Erland, how do use BATCHSIZE = 1? I don't have SQL server here right
now but wonder how to use BATCHSIZE. I use BULK INSERT. MAN! is it
quick.

TIA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 03:45 PM
Erland Sommarskog
 
Posts: n/a
Default Re: SQLDMO.Bulkcopy diagnostics on failed load

scoots987 (scoots987@gmail.com) writes:
> Erland, how do use BATCHSIZE = 1? I don't have SQL server here right
> now but wonder how to use BATCHSIZE. I use BULK INSERT. MAN! is it
> quick.


There is a sample command:

bulk insert fritte from 'C:\temp\slask.bcp'
with (datafiletype = 'char', fieldterminator = ',',
batchsize = 1, errorfile = 'C:\temp\slask.err')

BATCHSIZE = 1 is something you would only use for troubleshooting,
as it cut performance quite a bit.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:23 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com