Execute Query throws exception on Second Iteration in loop (against MS Access Database)

Hi Community,

I am facing an issue with Execute Query Activity. I have a simple select query (“Select * from Table1”) inside a while loop which runs fine on the first iteration. However, in the next iteration, it throws an exception “Execute Query: Object reference not set to an instance of an object”.

image

I then tried to use the Connect, Execute Query, and Disconnect activities. While doing this, again the first iteration went just fine. However, in the second iteration, the Connect activity threw an exception “Connect: External component has thrown an exception.”. I did supply the Database Connection handle to Execute Query and Disconnect Activities

UiPath Version: 2020.4.1
UiPath Database Activities Package version: 1.3.7369.25200
Database: MS Access

Your help would be greatly appreciated.

Thanks!

Hi @Umang_Gulati1 :wave:

Object reference usually happens when you are trying to access a method, or a property and it currently returns null. You said that you have given the Execute Query activity inside the while loop. Check if the while loop is returning certain value from each iteration (if you are getting table names, for example).

Hi @monsieurrahul
Thanks for your response.

At this point, I just have:

  • One while loop with condition “Counter < 5”
  • Inside the while loop, I just have one Execute Query activity (which creates the connection as well) and a simple static SQL query “Select * from Table1”

To answer your question, no, my query is not dynamic at all. Let me know what you think could be the issue?

image

1 Like

Alright then. Check the following:

  1. If a table named Table1 exists in your database.
  2. You have used the correct connection string.
  3. You have created a new instance of the output DT before entering the loop (if you are doing it dynamically)

Can you also post a screenshot of your error, if possible?

  1. Yes the table exists. Since the first iteration of the loop returns that data from the table correctly.
  2. Yes the connection string is also correct. Since the first iteration of the loop returns that data from the table correctly.
  3. Yes I have done that.

Which is the answer?