Solved

Detecting a specific error using OLE DB Provider for Jet

Posted on 2001-06-05
9
608 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 70

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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
 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

777 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