Solved

Detecting a specific error using OLE DB Provider for Jet

Posted on 2001-06-05
9
606 Views
Last Modified: 2012-08-14
Hi,

I am trying to detect a specfic error when adding a new record using the .AddNew method.

The table in question is from SQL Server, linked to an Access '97 Database - hence the OLD DB Provider.

My problem is that I cannot seem to extract a specific error code - in this instance a 3022 (duplicate record).

I have tried the standard VB error object and the ADO errors collection, but all I get is -2147217887 (error detected, big help).

I assume there must be an API call I must use or something but cannot figure out what it is.

Any help would be appreciated.

Thanks

Pete Brassett
0
Comment
Question by:pbrasset
9 Comments
 
LVL 2

Expert Comment

by:WalterM
ID: 6155913
In my experience, ADO is notoriously undescriptive about it's errors, cf. the well-known but useless "Errors Occured" message.

Have you tried examining the NativeError property of the ADODB Error object? This property will sometimes (...) return the original error ID as raised by the provider, e.g. the 3022 you mentioned above. No guarantees though.

Michel

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 6155936
Loop the Errors collection of the Connection object.
0
 

Author Comment

by:pbrasset
ID: 6155958
The NativeError property just returns a 3146 (ODBC Error - again, big help).

I have tried looping thru the errors collection which doesn't provide any more info.
0
 
LVL 2

Expert Comment

by:WalterM
ID: 6156322
I assume the "SQLState" property of the ADO error object doesn't return anything useful either?

Try this:

   On Error Goto ErrHandler:

   ... your code ...

ErrHandler:
   If Err.Number = 3146 Then ' ODBC Call failed
       MsgBox Error$
   End If

According to the Knowledge Base article Q120763, this should (...) return the original error description, followed by the original error number between parentheses.

Michel
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:pbrasset
ID: 6156502
SQLState gives the 3146, which doesn't help.

The err.number returned is -2147217887, while the error$ (and err.description) gives ODBC--call failed.
0
 
LVL 2

Expert Comment

by:WalterM
ID: 6156639
As a last resort, you could try to wrap the insert in a SQL-Server stored procedure, catching any errors there.

Other than that, I suspect you're out of options ;-(
0
 
LVL 2

Accepted Solution

by:
niklausj earned 50 total points
ID: 6157261
You say you linked a SQL Table into AccessDB then use the Jet-Ole-db-Provider ( from a VB app? ).
Problem is not OLEDB, but Accessing a remoteDB via Jet.
This hides the Actual Error, you'll get the Access ( JET ) interpretation of the OLEDB Error. Why can't you just connect directly to SQL via SQL-Driver (and If needed to Access via Jetdriver)from VB, this gives you the Error Raised in SQL-Server, not what Jet thinks SQL-Error was.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7132902
Hi pbrasset@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept niklausj's comment(s) as an answer.

pbrasset@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with my recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7167834
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now