473,508 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error handling when calling external sql-Files

I am using SQL Server 2000. I have some files with SQL-Statements.

The SQL-Serveragent runs jobs which execute the SQL-Files:
(e.g. osql /E /n /i \\server\d$\lager_pool.sql)

How can I implement an error handling.

If an error occurs, the script stops, and I can't read the variable
@error

My script - table xy doesn´t exist

SELECT * FROM XY
SELECT @@error
SELECT 33

The execution stops with an error after the first line

Thanks for your help.
aaapaul

Sep 30 '05 #1
3 1535
Hi

Look at using the -b flag when you call osql, there is more information in
Books Online.

John

<lv****@gmx.net> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
I am using SQL Server 2000. I have some files with SQL-Statements.

The SQL-Serveragent runs jobs which execute the SQL-Files:
(e.g. osql /E /n /i \\server\d$\lager_pool.sql)

How can I implement an error handling.

If an error occurs, the script stops, and I can't read the variable
@error

My script - table xy doesn´t exist

SELECT * FROM XY
SELECT @@error
SELECT 33

The execution stops with an error after the first line

Thanks for your help.
aaapaul
Oct 1 '05 #2
Thanks, but it doesn´t work

This is my script - its a file c:\test.sql

declare @errorcode int
select * from abc
SET @errorcode = @@error
--writing log
insert adaten.dbo.loghist(logdatum,loginfo,logfehler,saet ze)
values (getdate(),'test',@errorcode,25)

The table "abc" don´t exist.

If I call the script

osql /E /n /ic:\test.sql (with or without /b) the insert anweisung
instruction won´t be executed.

I want something like ON ERROR RESUME NEXT. Is this possible ?

Thanks
aaapaul

Oct 5 '05 #3
Hi

You may want to try using EXEC for your select statement

declare @errorcode int
EXEC ('select * from abc')
SET @errorcode = @@error
--writing log
insert adaten.dbo.loghist(logdatum,loginfo,logfehler,saet ze)
values (getdate(),'test',@errorcode,25)

John

<lv****@gmx.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Thanks, but it doesn´t work

This is my script - its a file c:\test.sql

declare @errorcode int
select * from abc
SET @errorcode = @@error
--writing log
insert adaten.dbo.loghist(logdatum,loginfo,logfehler,saet ze)
values (getdate(),'test',@errorcode,25)

The table "abc" don´t exist.

If I call the script

osql /E /n /ic:\test.sql (with or without /b) the insert anweisung
instruction won´t be executed.

I want something like ON ERROR RESUME NEXT. Is this possible ?

Thanks
aaapaul
Oct 8 '05 #4

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

Similar topics

12
6646
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
5
2545
by: claus.hirth | last post by:
If I create the function HELLO in schema S01 as follows, @ CREATE FUNCTION S01.HELLO() RETURNS VARCHAR(32) EXTERNAL NAME 'UDFSRVXYZ!sayHelloWorld' LANGUAGE JAVA PARAMETER STYLE DB2GENERAL NO...
1
8030
by: annie | last post by:
Hi all, I have recently ported my Access 2000 app to SQL Server, keeping the Access client as the front end using linked tables. I am also using triggers on my SQL tables to trap orphan...
16
2622
by: Steve Jorgensen | last post by:
I'm trying to figure out if there is a way to generate standard error handlers that "know" if the calling code has an error handler in effect (On Error Goto <label> or On Error Resume Next) before...
2
3003
by: Steve Jorgensen | last post by:
When writing VB or VBA code that works with databases or other external libraries that cannot be trusted to automatically do the right thing when references to their objects are arbitrarily...
3
2628
by: Alberto Giménez | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there! I'm doing some homework (almost finished), but now i'm reconsidering a design decission I made at the beginning. This is about error...
4
7600
by: James Radke | last post by:
Hello, I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module...
5
3612
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
2
2127
by: tshad | last post by:
This has been driving me crazy. I have been trying to get the error handling working on my system and can get parts of it working and others won't work at all. I found that you can't access...
1
6658
by: JDS | last post by:
I am getting the following error in my application: System.UnauthorizedAccessException was unhandled Message="Access to the port is denied." Source="System" StackTrace: at...
0
7135
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...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.