How to use Database Activities in UiPath.

Well use database activities in UiPath Studio is very simple. We get the following activities available in UiPath Studio after installing UiPath.Database.Activities Nuget package.

Now we will see how to use that activities step by step.

Connect:

First, we need to connect the database to UiPath Studio for that we just need to follow the below steps. Step 1.  Drag and drop “Connect” Activity from Activities Panel. Step 2.  Click on Configuration Connection as shown in the below image.

Step 3. Click on Connection Wizard. Step 4. Select the data source & Click on the OK button. Step 5.  In Connection Properties pane select the server name and choose the database as shown below.

Step 6. Click on Test Connection. If the popup shows Test Connection Succeed. You are done with the configuration if not you probably need to check the server name. Repeat the same step until you show the succeed popup. Now you are connected to the database. Note: In “Connect” Output properties you just need to create a variable for “Database Connection “So that you can use that variable in the entire project to avoid the repetitive task as shown below.

Execute Query:

This activity can be used when we want to fetch the data from the database. Like, select the entire data or specific data as per our need. The output will be saved in Datable which you can use for further data processing.

Step 1. Drag and drop “Execute Query” Activity from activities panel. Step 2. Click on Configuration Connection and enter the variable name which we have to create earlier in the “Existing database connection “field and click on the Ok button. Step 3. Now we need to enter the SQL Query to fetch the values from the database and create a variable to store the data in the output section as shown below.

Execute Non Query:

This activity can be used when we need to Insert / Update or Delete the values in the database table. We can create a variable to store the number of affected records.

Step 1. Drag and drop “Execute Non Query” Activity from activities panel. Step 2. Click on Configuration Connection and enter the variable name which we have to create earlier in the “Existing database connection “field and click on the Ok button. Step 3. Now we need to enter the SQL Query to Insert/Update/Delete the values from the database and create a variable to store the Number of affected Records in the output section as shown below.

Disconnect:

This activity can be used to close the database connection once we are done with modifying the database or initially when we complete the transaction. This activity would require the active connection variable to close the session.