473,396 Members | 2,010 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,396 software developers and data experts.

Get Row(s) in error MSSQL2005

Hi, I have a allready a try catch block around my sql execution (T-SQL) code.

1) Now in case of an error the server writes something like "could not insert duplicate key..." etc. Now it would be a tremendous help to know which row gave the error i.e. by returning the ID or the data of the columns in question.



2) Think this will probably not work but ... furthermore is there a way to get all of the problematic rows in question?
Sep 19 '08 #1
3 1369
ck9663
2,878 Expert 2GB
Where is the data coming from?

If it's coming from a table, do a
Expand|Select|Wrap|Line Numbers
  1. SELECT YOURKEY, count(*) FROM SOURCETABLE
  2. GROUP BY YOURKEY HAVING COUNT(*) > 1

You'll see those rows that has duplicate keys.

-- CK
Sep 19 '08 #2
Where is the data coming from?

If it's coming from a table, do a
Expand|Select|Wrap|Line Numbers
  1. SELECT YOURKEY, count(*) FROM SOURCETABLE
  2. GROUP BY YOURKEY HAVING COUNT(*) > 1

You'll see those rows that has duplicate keys.

-- CK
Thanks but I would like to display the rows in error when the error occurs - it could also be a foreignKey that needs to be inserted or a column that can't be null etc. So what I would like is to just return the values that caused the error - if this is possible.

The source is a db table, yes.
Sep 19 '08 #3
ck9663
2,878 Expert 2GB
If the error is a duplicate key, it's not a foreign key relationship problem.

If you really need to, try creating an INSTEAD OF TRIGGER. And direct the INSERTED table into a physical table.

-- CK
Sep 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wayne Pierce | last post by:
I have a small script with PHP that queries a MySQL database to pull out one row, where I want to be able to access each of the columns separately. I have tried several different variations and am...
23
by: Eva | last post by:
Hi i am trying to insert a new row into one of my datatabels that i have in my dataset when a button is clicked. here is my code Dim ClientInsRow As DataRow = dtClient.NewRo ...
1
by: Patrick Dunnigan | last post by:
Hi, I am attempting a bulk copy from a c program into SQL Server 2000 using DBLib in freeTDS 0.63 RC11 (gcc 3.4.3, RH 9). I am getting an error message that I cannot find any documentation on. ...
1
by: iam247 | last post by:
Hi I am a relative beginner with SQL and ASP. With some help after previous posts I have a page which successfully requests querystrings from another page and deletes a record from an access...
4
by: wackyphill | last post by:
I keep getting this error on a scheduling program I'm working on and don't know why. It seems to be the last row in the view always that gets the error. The Code W/ The Error: (_db is a wrapper...
3
by: Richard Marsden | last post by:
Here's another strange error I'm getting when using ODBC to access MySQL. This time ODBC is being more informative, although all the documentation I've looked at, claims that the function in...
0
by: kcm | last post by:
Hello all, Not sure if this is the right place to post this. I ran up the samples for adventureworks for MSSQL2005. I setup the shop front. The web site is up. But when I try to register a new...
3
by: Elmo Watson | last post by:
I previously had a project working, in which the Gridview was populated by a DataSet - then, with a DropDownlist in one of the columns, using the OnrowDataBound event, to populate the DDL with the...
2
by: azmiza | last post by:
Hi everybody, I need your help. I want to view my sql database and its work very well which is display in my web browser but once I want to press button yes, its not working, I check the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.