473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8029
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
2886
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
2260
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
2518
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
7215
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
1330
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
6707
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
2058
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
1112
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
2832
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...
0
7225
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
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7042
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
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.