473,372 Members | 921 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,372 software developers and data experts.

Return SQL error codes to Access app when using linked tables?

Hi all,

I have recently ported my Access 2000 app to SQL Server, keeping the
Access client as the front end using linked tables.

I am also using triggers on my SQL tables to trap orphan records and
validate added data.

My question is..

During testing, I created a form in Access to replicate what would
happen if a user tried to add data which did not conform to the rules
of the trigger.

In my error handling, I want to be able to grab the error that SQL
Server returns (not the standard Access error) but I can't seem to
figure out how to do this. The best I get is a message saying "3155
ODBC--insert on a linked table failed".

If I remove the error handling from the AddRecord procedure, I get the
correct error message from SQL Server. Good coding practice is that
you should always add error handling so I am reluctant to remove the
error handling procedure just to achieve my goal.

Does anyone know how to force Access to display the message that SQL
Server returns? It would probably be something like the
ADODB.ErrorValueEnum property.

Many thanks!

Annie
Nov 12 '05 #1
1 8020
DFS
Annie,

I needed a similar thing once - return meaningful SQL error message to
Access client.

My kludgey fix was this

* get the list of SQL Server errors and put it in a local Access table.
* use pass-thru queries - execute them from a error-trapped subroutine in
Access
* wrap the base SQL statement with TransactSQL code to trap errors and write
them to an error log table
* link to the error log table (WORK_ERRORS)
* when an error occurs, poll WORK_ERRORS for the Username and query the
error number against the local list of SQL error messages.

It works pretty good, actually, but it's a total kludge involving a SQL
error log table, a SQL rows affected table, and a separate local Access
table.

Public Sub alterODBCrecords(cSQL As String)

'THIS ROUTINE UPDATES THE PASS-THRU QUERY WITH THE SQL STRING PASSED INTO
THE SUB
'THEN IT SENDS THE PASS-THRU QUERY TO THE SERVER FOR EXECUTION
'ALSO TRACK THE NUMBER OF ROWS UPDATED, AND THE ERROR CODE IF ANY

On Error GoTo errAlterODBC

Set qItem = db.QueryDefs("Q_PASS_THRU")
qItem.ReturnsRecords = False
'TRAP ERRORS ON SQL SERVER - WRITE TO LOG TABLE. HANDLES ROWS AFFECTED
BETTER
qItem.SQL = "DECLARE @ERR int SET @ERR = 0 "
qItem.SQL = qItem.SQL & "DECLARE @ROWSAFFECTED int SET @ROWSAFFECTED =
0 "
qItem.SQL = qItem.SQL & cSQL 'THIS cSQL IS THE BASE SQL STATEMENT YOU
WANT TO EXECUTE
qItem.SQL = qItem.SQL & " SELECT @ERR = @@ERROR, @ROWSAFFECTED =
@@ROWCOUNT "
qItem.SQL = qItem.SQL & " UPDATE WORK_ROWS_AFFECTED SET RowsAffected =
@ROWSAFFECTED WHERE AppUserID = '" & getLoggedUser() & "'; "
qItem.SQL = qItem.SQL & " IF @ERR <> 0 BEGIN INSERT INTO WORK_ERRORS
(AppUserID, errorNum) VALUES ('" & getLoggedUser() & "', @ERR); END "

qItem.Close
qItem.Execute
exitAlterODBC:
Exit Sub

errAlterODBC:
globalErr = "pass-thru error"
'RETRIEVE SQL SERVER ERROR - LOGGED IN SQL TABLE VIA ABOVE
Dim odbcErr As Integer, Set rs2 = db.OpenRecordset("SELECT errorNum FROM
WORK_ERRORS WHERE AppUserID = '" & getLoggedUser() & "';")
odbcErr = rs2("errorNum")
rs2.Close

'REFER TO LOCAL TABLE TO GET ODBC ERROR DESCRIPTION
dim odbcErrDescription As Variant
odbcErrDescription = DLookup("ErrorDescription", "Sys_SQLErrorMessages",
"ErrorMsg = " & odbcErr & "")
if isnull(odbcErrDescription) then
odbcErrDescription = "Error " & odbcErr & ": error description not found
else
odbcErrDescription = DLookup("ErrorDescription", "Sys_SQLErrorMessages",
"ErrorMsg = " & odbcErr & "")
End If
MsgBox "SQL Server error " & odbcErr & ": " & odbcErrDescription
Resume exitAlterODBC
End Sub


"annie" <ro**********@hotmail.com> wrote in message
news:89**************************@posting.google.c om...
Hi all,

I have recently ported my Access 2000 app to SQL Server, keeping the
Access client as the front end using linked tables.

I am also using triggers on my SQL tables to trap orphan records and
validate added data.

My question is..

During testing, I created a form in Access to replicate what would
happen if a user tried to add data which did not conform to the rules
of the trigger.

In my error handling, I want to be able to grab the error that SQL
Server returns (not the standard Access error) but I can't seem to
figure out how to do this. The best I get is a message saying "3155
ODBC--insert on a linked table failed".

If I remove the error handling from the AddRecord procedure, I get the
correct error message from SQL Server. Good coding practice is that
you should always add error handling so I am reluctant to remove the
error handling procedure just to achieve my goal.

Does anyone know how to force Access to display the message that SQL
Server returns? It would probably be something like the
ADODB.ErrorValueEnum property.

Many thanks!

Annie

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Internet Arrow Limited | last post by:
Hi, I have a requirement to write an access application that must run under access97 and access2K. Some users will use Acess2K to access data that will also be accessed by Access97 users. The...
1
by: Mike Ridley | last post by:
I am trying to create a new query using 3 linked tables. As soon as I add the third table to the design grid Access crashes. I have looked in the newsgroup and find that there have been problems...
2
by: Vern Shellman | last post by:
We've got a form in Access 97 SR-2 that works fine with local tables. The pertinent VB code populating a combo box looks like this: Private Function ShowMOFInfo() Dim db As Database Dim rec...
15
by: brettclare | last post by:
I have linked a large SQL Server table to Access, however 'only' 2,195,439 records are shown and are available to query. Can I increase the size (cache??)/number of records showing in Access? ...
0
by: gbradford3 | last post by:
I can pull up an MS Access database, link DB2 tables to it (using a System DSN) and create queries that return differences between a MS Access table and a DB2 table. I am able to query both the MS...
10
by: Robert | last post by:
How do you get an accurate count of the number of records returned from a query when using linked tables. I have an access 2003 database as a front end to another access 2003 database that...
1
by: boris_amj | last post by:
Help, I have an Access database with link tables to a SQL Server 2000 database. When I run the following query, it works OK: SELECT Format(,"mmmm yyyy") AS DateTXT, Sum(='CANCELLED') AS...
0
by: Nathan | last post by:
I have an access DB on the web server i am running my webapp through. I want to use it, however it has linked tables to other access DBs on that same server. VWD doesn't like it because the links...
1
by: imnewtoaccess | last post by:
Hi, SELECT TK_TURN_DAILY_DETAIL1.DATE, TK_TURN_DAILY_DETAIL1.USH_REVENUE AS TDL_Revenue, TK_TCK_SALE_DETAILS1.USH_REVENUE AS TSD_Revenue, - AS Expr1, TK_TCK_SALE_DETAILS1.TK_SERIAL AS...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.