Solved

How to catch SQL error return by a query running in Access

Posted on 2009-05-06
6
280 Views
Last Modified: 2012-05-06
Hi all,

I am working on an Access project, which will migrate data from Access to SQL Server. I do it through Append query. The issue is that, the append query sometimes couldnt insert a particular row from Access to SQL Server (I know the reason is datatype confliction), but Access didnt error out this error and just skip this row. My question is is there anyway I can catch this error, try to modify the data to be datatype-matched, and then re-insert to SQL Server table.
I tried to look for solution but havent found yet. If anyone have idea, I would appreciate.

Regards,
0
Comment
Question by:jjdahl
  • 4
6 Comments
 
LVL 84
Comment Utility
How are you running your append query? Is this a query that you've built in the Access database, or are you opening a connection to the server, running a Stored Proc on the server, etc etc ...
0
 
LVL 84
Comment Utility
Also, IMO you really should validate your data BEFORE you attempt your append - that is, using VBA, you'd examine your data to insure that you can correctly insert before you attempt to do so.
0
 

Author Comment

by:jjdahl
Comment Utility
HI LSMConsulting,

I create append queries in access, with linked tables to SQL Server. Also, I create a program that automatically run those append queries.
 
This is a big migration with hundreds of table, that's why I cannot check every case to make sure data is correct. Detect the data mismatch and show it out is a part of the project too.

Thanks for your response
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 84
Comment Utility
You could build queries that would be run AFTER your insert, to show which records haven't been inserted. for example:

SELECT * FROM YourSQLTable WHERE YourIDField NOT IN (SELECT IDfield FROM YourAccessTable)

Of course, you may need to use more than one field in the subselect to get the right results, but then I'm not sure of your table structure.
0
 
LVL 18

Accepted Solution

by:
jmoss111 earned 500 total points
Comment Utility
Why would you even want to insert incorrect data into a table if you could? Build staging tables, do hygiene on the staging tables then insert into prod tables.
0
 
LVL 84
Comment Utility
Exactly ...
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 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

10 Experts available now in Live!

Get 1:1 Help Now