Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Different Error Numbers for same error! 1

Status
Not open for further replies.

MadJock

Programmer
May 25, 2001
318
GB
Hi,

Got a bit of a wierd situation. I have some VB code that connects to SQL Server 2000 via OLEDB.

I then use a command object to call an SP to insert values into a table. So far so good.

When the item I am trying to insert already exists in the table, I trap error -2147217873 (Violation of primary key) and report to user that the item they are trying to add already exists.

This works fine when in debug mode on my NT4.0 machine. However when I build the app and run it on a W2K machine, the error number for Violation of Primary Key becomes -2147217900.

I would expect the error number to be the same as I was under the impression that the SQL server generates and returns the error. (Or could it be different MDAC versions / OLEDB versions?)

I can trap both errors but would be happier if I knew why they were different.

Any advice would be much appreciated.

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 

Folks,

If it's of any interest, I've came to a conclusion.

The -214 error shows an automation error. As ADO is being used here that shows the error is generated by it.

Making a bit of a jump to say that the different error number is generated because the W2K box has a different ADO version.

Cheers,

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 
Hi,

I may be answering a bit quickly here, but wouldn't the NativeError property return a valid (and consistant) number for your Error Handling routine ?

Droops
 

Sorry droops - not familiar with the NativeError property.

To which object does this property belong? I've had a look in the command object and the connection object and cannot see it.

Thanks,

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 
the ADO Connection Object has an Errors collection.

When an error raises, it is in fact, a certain number of errors that are stored in this Collection. Some will stop the current process, others won't (warnings, information, ...)

Usually the first error in the collection is enough to determine what has happened. In other cases, you may have to iterate through the Errors collection and check their properties for relevant error messages/codes.

This example from MSDN was useful to me.
Hope it helps you.


Droops
 
Hello to all,

thank you for the star, I am glad this helped someone. :)
Tek-Tips Forums have already pointed me in the right direction a number of times : It's nice to be able to give a little and not just take.


Take care.


Droops.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top