Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-06
6
Medium Priority
?
293 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 85
ID: 24320228
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 85
ID: 24320234
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
ID: 24320371
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 85
ID: 24320685
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 1500 total points
ID: 24321178
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 85
ID: 24321285
Exactly ...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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