Questions tagged [error-handling]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
26 views

Can I redirect rows on error in SSIS if the error happens within an "if condition", not while writing the column value?

I know how I redirect rows on error or truncation. That works if you have an error while you insert a value into the column. Truncation: Say you have a string of 10 characters and you insert it into ...
questionto42's user avatar
2 votes
1 answer
160 views

Catching exceptions and rolling back transactions

I am just trying to see if I understand this correctly: By default, any error occurring in a PL/pgSQL function aborts execution of the function and the surrounding transaction I have a procedure ...
Lugoom485's user avatar
0 votes
3 answers
73 views

How to exit the Azure SQL script to skip all remaining batches?

I have a Python script that glues together individual SQL scripts like: creating tables, creating views, creating functions, creating stored procedures... It produces the single installation SQL ...
pepr's user avatar
  • 143
0 votes
1 answer
104 views

Error handling - stored procedure nested in another stored procedure

I've got a stored procedure that call another stored procedure. And i sometime get an error : System.Data.SqlClient.SqlError: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION. At ...
dexon's user avatar
  • 47
0 votes
0 answers
62 views

MySQL 8: show deprecated error only as warning

I'm migrating MySQL from 5.7 to 8.0.32. I know character set utf8mb3 and its collations are deprecated. But we have lots of functionality and data with utf8mb3, and we don't have more time to change ...
yaki_nuka's user avatar
  • 141
1 vote
1 answer
172 views

Handle partial failures in a transaction (commit selectively) in MSSQL

I am doing a batch update where I process records sequentially (User 1, User 2 etc). Each record has multiple update queries associated to it. I need to skip if there is a data issue for an individual ...
Nishant's user avatar
  • 869
2 votes
1 answer
256 views

How to cause a SQL Server database integrity error

I have created a stored procedure that uses dbcc checkdb on all userdatabases, if there are any errors detected it then collates the errors and formulates a html table and sends an html email to ...
BLoB's user avatar
  • 153
1 vote
1 answer
302 views

Lost connection to the database during COMMIT query: did the transaction succeed or not?

PROBLEM I recently encountered the error 2013 in MySql (Lost connection to MySQL server during query) while executing the COMMIT statement for a transaction (the previous update statements succeeded). ...
bruno-kakele's user avatar
0 votes
2 answers
1k views

Try Catch w/Transaction and executing stored procedures

I need to create an error-handling method for a couple of Stored Procedures. Proc1 CREATE PROCEDURE dbo.Proc1 AS BEGIN TRY BEGIN TRANSACTION EXEC Proc2 INSERT INTO tableA (col1, col2) ...
Semperfi89's user avatar
0 votes
1 answer
615 views

Logging in error states in Postgres transactions

I'm currently working on rebuilding some SQL Server stored procedures in Postgres, but I have the following hangup CREATE OR REPLACE PROCEDURE public.math_proc () LANGUAGE plpgsql AS $$ BEGIN ...
Rushabh Mehta's user avatar
0 votes
2 answers
273 views

WHILE EXISTS Error Handling/ Raise Error

I am adding a step in my SQL job where it does a WHILE EXISTS check for me before executing the last step. What it does is it will wait for 15minutes to see if the table I am checking has been ...
WhoIsNotActive's user avatar
-2 votes
1 answer
840 views

PSQL avoid insert failing because a trigger failed

I want to put a trigger on a table, the code itself could work sometimes, while sometimes it might fail unexpectedly. So I need the data to get inserted on the table regardless if one of its triggers (...
Eugenio.Gastelum96's user avatar
0 votes
1 answer
2k views

Routinely deleting data from tables using stored procedure

I've created a maintenance stored procedure to delete data older than 30 days on events table. What are the best practices for deleting data? I've encased the procedure with error handling, i.e. TRY......
dexon's user avatar
  • 47
0 votes
0 answers
44 views

Filter out non date values from date values in postgresql

I receive data in text format for dates, some wrong entries are also present for eg. date 30-02-2022 which doesn't exist. So when I try to cast text into dates, it fails with an error. I thought of ...
Nikhil Yadav's user avatar
6 votes
1 answer
671 views

Why do permission errors doom a transaction with XACT_ABORT set to OFF and ANSI_WARNINGS set to ON?

Consider the following T-SQL in which the user doesn't have permission to execute SP_TRACE_GENERATEEVENT: SET XACT_ABORT OFF; SET ANSI_WARNINGS ON; BEGIN TRANSACTION; BEGIN TRY EXEC ...
Joe Obbish's user avatar
  • 32.2k
-4 votes
1 answer
84 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, ...
Wen Hui Wong's user avatar
2 votes
2 answers
616 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 ...
adam.g's user avatar
  • 355
1 vote
2 answers
3k 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 ...
SQL RV's user avatar
  • 11
0 votes
0 answers
192 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 ...
Metaphor's user avatar
  • 896
1 vote
1 answer
5k 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 ...
Adam Mulla's user avatar
3 votes
3 answers
14k 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: ...
Pantea's user avatar
  • 1,412
6 votes
2 answers
435 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) ...
JohnG's user avatar
  • 1,081
4 votes
3 answers
1k 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 ...
Robert Carnegie's user avatar
0 votes
0 answers
66 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 ...
Lumpy's user avatar
  • 2,109
16 votes
1 answer
28k 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 ...
user15080516's user avatar
-2 votes
2 answers
146 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?
Lightsout's user avatar
  • 109
2 votes
3 answers
4k 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 ( ...
Wilmar's user avatar
  • 173
0 votes
2 answers
301 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 ...
Big ol' PGphant's user avatar
1 vote
1 answer
1k 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 ...
JohnG's user avatar
  • 1,081
0 votes
1 answer
188 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 ...
RonJohn's user avatar
  • 615
1 vote
2 answers
481 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, ...
Stalinko's user avatar
  • 181
0 votes
2 answers
688 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....
tmangin's user avatar
  • 101
6 votes
1 answer
2k 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 ...
Morris de Oryx's user avatar
-1 votes
1 answer
321 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 ...
Floobinator's user avatar
3 votes
1 answer
238 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 ...
Petter Brodin's user avatar
1 vote
1 answer
171 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? ...
J.D.'s user avatar
  • 37.5k
0 votes
0 answers
31 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 ...
Zoltán Schmidt's user avatar
2 votes
0 answers
295 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 ...
Cade Roux's user avatar
  • 6,602
25 votes
1 answer
67k 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.
FastTurtle's user avatar
6 votes
1 answer
3k 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 ...
Elaskanator's user avatar
0 votes
1 answer
498 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, ...
Marcello Miorelli's user avatar
2 votes
1 answer
186 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,...
slowjams's user avatar
  • 223
0 votes
1 answer
785 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 ...
Eric Swiggum's user avatar
2 votes
1 answer
593 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 ...
SQL_NoExpert's user avatar
  • 1,049
1 vote
0 answers
671 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 ...
René Nyffenegger's user avatar
5 votes
1 answer
413 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 ...
Freiheit's user avatar
  • 259
1 vote
1 answer
8k 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 ...
user avatar
0 votes
0 answers
6k 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 ...
igelr's user avatar
  • 2,132
2 votes
0 answers
750 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 ...
Augusto's user avatar
  • 121
0 votes
1 answer
2k 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 ...
user avatar