Questions tagged [error-handling]
The error-handling tag has no usage guidance.
133
questions
-4
votes
1
answer
51
views
Finding the errors in SQL and interpreting what the SQL codes mean
Find all 5 errors in the SQL script below and explain what the script is trying to do
select
A.BIZ_DT,
A.ACTL_PARENT_SVC_NUM,
A.DIRCTN_IND,
A.BUS_STOP_CD,
A.BUS_STOP_ARRVL_TM,
A.OPR_ID_NUM,
A.REG_NUM,
...
2
votes
2
answers
218
views
How to simulate error with MSG = 0 on Sql Server?
I need to simulate error on Sql Server:
“Msg 0, Level 20 A severe error occurred on the current command”
because our developers have to handle it in application.
How can I simulate/trigger this kind ...
0
votes
1
answer
294
views
Postgres: Insert all valid data into a table while logging errors
I am attempting to devise a method that will enable me to load data into a table which will load all valid data and log the invalid records. Ideally, I'd like to do this without looping through the ...
0
votes
0
answers
87
views
How to save the error returned by a stored procedure
I am trying to figure out how to get the error message returned from the proc sys.sp_testlinkedserver rather than the non-descriptive message returned by ERROR_MESSAGE().
The proc's message is:
OLE ...
1
vote
1
answer
435
views
How to use user defined exception - PostgreSQL Function
Can you please provide syntax for to use user defined exception in PostgreSQL function?
Suppose I want to handle below user defined exception.
SQL Error [22023]: ERROR: password is too short.
There ...
2
votes
3
answers
2k
views
How to solve error "ORA:01-006 :bind variable does not exist" when working with bind variables?
I have a table with below structure and data :
create table TEST_TABLE
(
item_number NUMBER,
item_name VARCHAR2(50),
item_col VARCHAR2(50),
item_pol VARCHAR2(50)
)
Sample data:
...
4
votes
2
answers
129
views
Multiple Set Quoted_identifier within one script takes the last one?
I'm using SQL Server 2019 and just found a weird behaviour.
Research has not gotten me anywhere further.
Can someone please explain this behaviour?
SET QUOTED_IDENTIFIER ON;
if ((256 & @@options) ...
4
votes
3
answers
607
views
MS SQL Server 2014: which stored procedure is my error in?
As a general question or three on Microsoft SQL Server 2014, that perhaps I should know the answer to already, or even perhaps did once -
When my stored procedures run other stored procedures, how can ...
0
votes
0
answers
17
views
Get real error from backup job failure instead of backup terminating abnormaly
I've had log backup jobs fail for a few different reasons lately. When I go to the job it tells me backup terminated abnormally. However, when I run the backup script in SSMS it will tell me the ...
1
vote
1
answer
1k
views
Is "deadlock detected" really an error? Should I be suppressing them after handling them?
A while ago, I spent a nightmarish number of weeks dealing with "deadlock detected" and trying to figure out how to handle it. I ended up finally handling it in such a manner that my code is ...
-2
votes
2
answers
43
views
Best way to double check query results are right on large tables [closed]
When you write SQL query between big tables what is a good way to check that you have the correct query when the resulting table is 2000+ lines?
1
vote
3
answers
974
views
BULK INSERT continue on PRIMARY KEY error
I get a CSV file with a several million records every few days. I need to insert them into our database. What I do is quite straightforward:
BULK INSERT dbo.activity
FROM 'C:\tmp\activity.csv'
WITH (
...
-1
votes
2
answers
111
views
How do I make PostgreSQL not log specific errors?
ERROR: deadlock detected at character 13
My PG log is full of this, but the thing is, I already handle it (after years of frustrations) in my application. I detect them and repeat until they go ...
1
vote
1
answer
349
views
TSQL success or failure result of EXEC dynamic SQL
Based on the following code:
/* This SP takes a query and a unique temporary table name as input...
The outputs is a string with the command to create the tmp table based on the query that is given ...
0
votes
1
answer
89
views
TRY/CATCH only reports the last (and most useless) error
(This is SQL Server 2016 SP2-CU12.)
When running this command interactively, I see the quite useful Msg 3035, Level 16, State 1.
BACKUP DATABASE @DB TO DISK = @targetfile
WITH DIFFERENTIAL, RETAINDAYS ...
0
votes
2
answers
174
views
How to make MySQL 8 alert when integer overflow happens during INSERT ... ON DUPLICATE KEY?
Let's consider we have a simple table with auto-incrementing integer ID and some unique column:
CREATE TABLE `test` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`value` tinyint DEFAULT NULL,
...
0
votes
2
answers
54
views
How to catch all the errors happening during the execution of an SQL file containing multiple INSERT INTO statements to insert multiple rows?
I've got a sql file TW_popul.sql containing multiple INSERT statement:
INSERT INTO conversion_fee (FEE_ID, FEE_AMOUNT, DISCOUNT_AMOUNT, FEE_TYPE, PAYMENT_ORDER_ID)
VALUES (32353357, 8.67, 0, 'com....
4
votes
1
answer
861
views
Custom error code class and numbers for Postgres stored functions
I'm writing a collection of stored functions in Postgres 11.5, and want to RAISE EXCEPTION when various pre-conditions are not met. For example, a null or empty string with a string is required, or an ...
-1
votes
1
answer
219
views
Every Attempt at Error Handling Fails with GET
UPDATED (12.3.2019)
I'm using MySQL 8.x and every attempt at putting any error handling that provides internal details fails on the "GET" (red highlight) stating:
GET is not valid at this position
...
3
votes
1
answer
163
views
Getting all undeclared variables from query
Imagine you try to run the following query:
SELECT *
FROM dbo.Customers c
WHERE id = @id
AND dateTimeCreated = @date
You'll get an error message along the lines of Must declare the scalar ...
1
vote
1
answer
78
views
Do a lot of error checks affect query performance and is it bad practice?
If I have a stored procedure with a handful of error checks that come before the queries are executed and throw exceptions as necessary, could this affect performance? Is it bad practice to do this?
...
0
votes
0
answers
26
views
Is it possible to create an SQL transaction that rollbacks on syntax errors?
In may day-to-day job, I often have to create SQL files containing minor changes (no DDL operation usually) in order to migrate those to production databases easily.
The problem is, even with syntax ...
2
votes
0
answers
186
views
Catching QUOTED_IDENTIFIER Errors in Trigger without aborting transaction
Is there a way to catch a QUOTED_IDENTIFIER error without failing the transaction?
I have assembled a minimal test case here. The trigger must have SET QUOTED_IDENTIFIER ON because it uses XML data ...
18
votes
1
answer
38k
views
Try catch equivalent in Postgres
Do we have a try catch equivalent in Postgres? I have written some user defined functions that are called by trigger. I (don't) want to ignore errors so that flow does not get interrupted.
6
votes
1
answer
1k
views
SQL Server - TRY/CATCH does not work in certain cases
How can I write guarded code that invokes the CATCH code block in every expected* case (without doing funky junk like wrapping everything in dynamic SQL)?
For example, this does not work:
Define a ...
0
votes
1
answer
268
views
how to convert from raiserror to throw in the current context?
I have a function that checks is the file is present on disk in an specific location.
Using that function I am checking for the latest backup, in the code below.
If we don't have a backup anymore, ...
2
votes
1
answer
104
views
why the processing is sometimes terminated , sometimes not
DECLARE @Error int;
INSERT INTO Person.BusinessEntityContact
(BusinessEntityID
,PersonID
,ContactTypeID)
VALUES
(0,0,1);
SELECT @Error = @@ERROR;
PRINT ‘The Value of @Error is ‘ + CONVERT(varchar,...
0
votes
1
answer
455
views
Why is my TRY CATCH block in SQL Server immediately exiting on error completely ignoring the remaining code in the block, including my error handling?
Below is a snippet of my TRY/CATCH logic within a stored procedure with error handling (I did not include all of the DECLARE statements). This is being ran within a stored procedure, however I am ...
2
votes
1
answer
213
views
Object id error in sql server
I want to know the object referenced as an associatedObjectId in a deadlock graph, so I ran the below query:
SELECT OBJECT_NAME(1234560112364076)
I get the following error:
Arithmetic overflow ...
1
vote
0
answers
277
views
Can I force a LOAD DATA LOCAL statement to abort if an error is not loaded?
I am trying to load a CSV file into a MySQL table with the load data local statement. After loading it, the statement reports
Query OK, 1030 rows affected, 7314 warnings (0.03 sec)
Records: 1043 ...
3
votes
1
answer
250
views
Does the "don't use errors for flow control" axiom apply to postgres?
In traditional programming there is an axiom that states, "do not use errors for flow control". A general example is to throw an error then catch the error instead of using an ordinary conditional ...
1
vote
1
answer
5k
views
SQL Creating Error Log Table Benefits
We are conducting a datawarehouse project, moving data from Staging database to Kimball Data Warehouse.
What is the purpose of creating a custom stored procedure Error Log Table?
I am seeing a lot ...
0
votes
0
answers
4k
views
SQL Server Error 14013 - This database is not enabled for publication
I am trying to configure a database publication with T-SQL.
use master
exec sp_replicationdboption
@dbname='anun',
@optname=N'publish',
@value = N'true';
It runs successfully and I see ...
2
votes
0
answers
400
views
How get process that is locking Database on SQLite?
I'm developing a iOS app using SQLite. I've got a class to manage SQL's operations, basically read, write and update. In many cases I get a SQLITE_BUSY error, so I want know which process is using the ...
0
votes
1
answer
915
views
Find if Stored Procedure Error
Is there a method in T-SQL to see if error occurred in Stored Procedure, without the use of @Output or try catch?
We have a lot of legacy code 200+ stored procedures. I have seen @Output method and ...
1
vote
1
answer
100
views
How to index of filter extended event files in Sql Server
I am collecting errors data using the error_reported event and saving the data on XEL files. The problem is that there are hundreds of thousands of errors over there and querying them can take a lot ...
0
votes
2
answers
330
views
Impossible to log errors after dooming a transaction within an INSERT-EXEC statement
We have a stored procedure that does some work within a transaction, wrapped within a stored procedure that returns some result data using the INSERT-EXEC method of sharing data.
After observing the ...
1
vote
1
answer
359
views
Should SQL Server 2000 throw an error if update statement fails within a SP?
I'm troubleshooting an issue on SQL Server 2000 where it appears that a update statement in a stored procedure failed, and the check for @@ERROR <> 0 didn't catch it, so the transaction was ...
0
votes
2
answers
77
views
how to run once a bunch of generated scripts with exception handling?
Before I restore a database, I need to save the contents of a table called dbo.ref_systemSettings if it exists.
So I created a script that calls a procedure that will save the contents of this table ...
0
votes
1
answer
57
views
job send email to developers upon complexion and include DBAs if it fails
I have a job that sends an email to an operator (which contains a list of emails within it) upon complexion.
Some of these people that are on that list are the developers who build everything in that ...
0
votes
0
answers
857
views
SSIS: Using Event Viewer to Trace Errors of A Package
Overview
A package was developed due to a planned database server migration, and other teams with a dependency on legacy cross-database queries. There is a policy of not having Linked Servers, so an ...
3
votes
1
answer
3k
views
SQL Server TRY..CATCH resume on terminating error
I'm trying to get a master stored procedure to execute through to completion, where the master SP calls child SPs to perform modular tasks that are independent of each other (i.e. - if one fails, that ...
2
votes
4
answers
815
views
SQL Server - Any way to validate insert statements for mismatching column names?
I like to be verbose in my coding, so my typical insert statement looks like this:
INSERT INTO MyTable
(
Column1
,Column2
,Column3
,Column4
,Column5
,Column6
)
SELECT
...
0
votes
0
answers
2k
views
SQL Server - What is the RAISERROR substitution parameter for boolean/bit type?
I'd like to quickly dump some context into an error message including some boolean flags using the handy-dandy substitution parameters of RAISERROR such as
CREATE PROCEDURE MyProc
(
@param1 INT = ...
0
votes
1
answer
1k
views
SQL Server Profiler Exception tracing - Error procedure and line number omitted
Is there a trace configuration or setting that will enable the profiler to output ERROR_PROCEDURE() and ERROR_LINE() information that is always available when writing manual error handling in CATCH ...
1
vote
2
answers
11k
views
How to rollback a SQL Server transaction and use output param?
I am trying to set an output param in a stored procedure, but I think that when I rollback the transaction I think I'm also rolling back the assignment to @out. Is that correct?
If so, how can I ...
0
votes
2
answers
5k
views
How to avoid primary key violation while doing inserts
I have a code which does insert into destination table from source, but at times we are ending up with deadlocks.
Due to deadlock , I have to rerun this code again.
while i do re-run , I end up with ...
17
votes
6
answers
19k
views
PostgreSQL alternative to SQL Server’s `try_cast` function
Microsoft SQL Server has what I consider a remarkably sensible function, try_cast() which returns a null if the cast is unsuccessful, rather than raising an error.
This makes it possible to then use ...
3
votes
2
answers
2k
views
MySQL Stored Procedure not throwing error if it contains a query that succeeds
I am writing a simple MySQL Stored Procedure, and calling it from PHP using PDO.
This is just simple enough to illustrate the problem I'm having.
This procedure test_procedure_2, does not throw any ...
6
votes
6
answers
35k
views
SSPI handshake failed with error code 0x8009030c, state 14
DESCRIPTION: SSPI handshake failed with error code 0x8009030c, state 14 while establishing a connection with integrated security; the connection has been closed. Reason: AcceptSecurityContext ...