Home All Groups Group Topic Archive Search About

BCP output perfect one minute, corrupt the next!

Author
4 Aug 2006 12:31 PM
Matt Smith
Hello,

I have little experience with SQL Server, but I've written a stored procedure
that extracts basic demographic information to be imported into another system.
I'm using a batch file as a scheduled task that extracts the data via bcp.  The
batch file looks similar to this:

bcp "exec RetrieveStudents '0607'" queryout c:\data.txt -c -U username -P
password

Some of the time, the query works just fine, and I have perfect, tab-delimited
data in my file.  But other times, though the file size still looks accurate,
the entire file contains nothing but garbage characters, like this section that
I snipped:

敥䄉䥋华††††††††††䠉剁奒†††ठठ㌲‰䅍佃⁎䑒

Can you give me any advice as to why this query would produce valid data one
minute, and these other characters the next?

Thanks,

Matt Smith
Assistant Director, IT
DeSoto County School District
Arcadia, Florida

Author
4 Aug 2006 10:34 PM
Erland Sommarskog
Matt Smith (Matt_mem***@newsguy.com) writes:
> I have little experience with SQL Server, but I've written a stored
> procedure that extracts basic demographic information to be imported
> into another system. I'm using a batch file as a scheduled task that
> extracts the data via bcp.  The batch file looks similar to this:
>
> bcp "exec RetrieveStudents '0607'" queryout c:\data.txt -c -U username -P
> password
>
> Some of the time, the query works just fine, and I have perfect,
> tab-delimited data in my file.  But other times, though the file size
> still looks accurate, the entire file contains nothing but garbage
> characters, like this section that I snipped:

That's rude.

I can't really say what is going on, but I have gotten impression that
queryout is flaky. Could you have the stored procedure to produce the
data into a table and then extract from that table?


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
5 Aug 2006 12:08 AM
Steve Kass
Matt,

The extract you posted is not quite the garbage you think it is. In fact,
it contains recognizable names (last name first, all caps) and numbers.
I can only guess what it looks like to you, since it came through
half-converted
into escape codes for Unicode characters, but since you say "nothing but
garbage characters," I'll guess you see mostly Chinese characters.

The single bytes that these Unicode characters represent actually make
sense, so the problem might lie with your text file reader.  Are you by
chance discovering this problem when you view the file in a program
that might have the gall to guess at the appropriate character encoding,
like a browser or word processor, and not in a program designed just
for text files? It looks to me like the problem is one of interpretation,
not of content. To make an analogy, if you loaded this text file into your
MP3 player, it wouldn't sound very good, but that doesn't mean it's garbage.

If you haven't yet, try opening the file in notepad and see what you see.

If I'm right, the answer to your question of why it would produce valid
data one minute and garbage the next has to do with how your viewer
guesses at the right encoding. If you happen to have character pairs at
the beginning of the file that make sense as common Chinese characters
if interpreted in Unicode, someone might think your file is in Chinese.

Steve Kass
Drew University
www.stevekass.com

Matt Smith wrote:

Show quote
>Hello,
>
>I have little experience with SQL Server, but I've written a stored procedure
>that extracts basic demographic information to be imported into another system.
>I'm using a batch file as a scheduled task that extracts the data via bcp.  The
>batch file looks similar to this:
>
>bcp "exec RetrieveStudents '0607'" queryout c:\data.txt -c -U username -P
>password
>
>Some of the time, the query works just fine, and I have perfect, tab-delimited
>data in my file.  But other times, though the file size still looks accurate,
>the entire file contains nothing but garbage characters, like this section that
>I snipped:
>
>敥䄉䥋华����������䠉剁奒���ठठ㌲�䅍佃⁎䑒
>
>Can you give me any advice as to why this query would produce valid data one
>minute, and these other characters the next?
>
>Thanks,
>
>Matt Smith
>Assistant Director, IT
>DeSoto County School District
>Arcadia, Florida
>

>

AddThis Social Bookmark Button