473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trapping BCP error from SP

HI

I am using the following code in an SP, it seems like an ugly hack I
have done to check if the BCP was working or not, I check the table it
shold have filled instead of checking the error from BCP itself.

Does anyone know how I can check the BCP errors directly?

this is the code I am using.

--------------------------------------
create procedure q_spr_autoinventering

AS

create table ##q_tbl_autoinventering (

ean13 varchar(13),
antal decimal,
signatur varchar(10),
lagstalle int
)

exec master..xp_cmdshell"bcp ##q_tbl_autoinventering in
c:\outpath\hd1\invent.txt -t ; -Usa -P13hla -c -C "

declare @invjournal int,
@lagstalle int,
@invdatum datetime,
@ean13 varchar(15),
@antal decimal,
@artnr varchar(50),
@lagplats varchar(20),
@lagsaldo decimal,
@mysubject nvarchar(4000)

IF EXISTS (select * from ##q_tbl_autoinventering)
begin
-----------------------------------------------

it seems so ugly to check the table instead of the BCP error itself so
any pointers would be gladly appreciated, I tried to check @@error but
that did not seem to worked how I needed it.

in short what I want is this

if bcp did not work break out of the SP and wait until called next
time by sql server agent. and by not working I only mean that there
was no file to fetch, if there is a file to fetch and the table is
created I have lots of checks in the SP to make sure the values are
correct

rgds

Matt
Jul 20 '05 #1
1 7464

"Matt" <ma**@fruitsalad.org> wrote in message
news:b6*************************@posting.google.co m...
HI

I am using the following code in an SP, it seems like an ugly hack I
have done to check if the BCP was working or not, I check the table it
shold have filled instead of checking the error from BCP itself.

Does anyone know how I can check the BCP errors directly?

this is the code I am using.

--------------------------------------
create procedure q_spr_autoinventering

AS

create table ##q_tbl_autoinventering (

ean13 varchar(13),
antal decimal,
signatur varchar(10),
lagstalle int
)

exec master..xp_cmdshell"bcp ##q_tbl_autoinventering in
c:\outpath\hd1\invent.txt -t ; -Usa -P13hla -c -C "

declare @invjournal int,
@lagstalle int,
@invdatum datetime,
@ean13 varchar(15),
@antal decimal,
@artnr varchar(50),
@lagplats varchar(20),
@lagsaldo decimal,
@mysubject nvarchar(4000)

IF EXISTS (select * from ##q_tbl_autoinventering)
begin
-----------------------------------------------

it seems so ugly to check the table instead of the BCP error itself so
any pointers would be gladly appreciated, I tried to check @@error but
that did not seem to worked how I needed it.

in short what I want is this

if bcp did not work break out of the SP and wait until called next
time by sql server agent. and by not working I only mean that there
was no file to fetch, if there is a file to fetch and the table is
created I have lots of checks in the SP to make sure the values are
correct

rgds

Matt


Check the return code from xp_cmdshell:

declare @ret int
exec @ret = master..xp_cmdshell ...

The return code will be 0 if BCP ran without error, or 1 if there was an
error. If invent.txt exists but has no data in it, you'll get a return code
of 0, but it sounds like your checks will catch that anyway.

Simon
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Pete | last post by:
I'm trying to improve my code so that when I open a recordset object, I can absolutely guarantee it is closed and is set = Nothing. I have read some old threads and they all say to use the...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
1
by: Elmo Watson | last post by:
Up until now, I've done all the work (gui/front end programming, classes, etc) I've done all my error trapping (try/catch) in the methods in the code behind. Now I've got an opportunity to do...
1
by: jan.loucka | last post by:
I'm developing WinForms application in .NET 2.0 that talks to web service. The automatically generated proxy (reference class) has got methods for both synchronous and asynchronous invocations of...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.