How to run .sql file in uipath

Hi Team,

I have one SQL file and inside the file multiple queries are present. i want to run .sql file queries one by one.
Please help me how to run .sql file?

Hi @Smitesh_Aher2

Use the below package for the DB activities
image

*Read the content of your .sql file into a UiPath string variable using the ‘Read Text File’ activity.

  • Split the content of the file into individual SQL queries. You can use the String.Split method in UiPath to split the content based on the query delimiter (e.g., ; )
    *Use a ‘For Each’ activity to iterate over the array of SQL queries
    *Inside the loop, use a database activity (e.g., ‘Execute Query’ or ‘Execute Non-Query’) to execute each SQL query against your database.
    In assign activity use the split method to seperate the content

Regards

Hi @Smitesh_Aher2

In UiPath, you can use the “Execute Query” activity to run SQL queries from a .sql file.
For this you need to install UiPath.Database.Activities from packages

Main
|-- Connect (establish database connection)
|
|-- Read Text File (File: YourSQLFile.sql)
| |-- Output: sqlFileContent
|
|-- Assign (queriesArray = sqlFileContent.Split(";"c))
|
|-- For Each (item in queriesArray)
| |-- Execute Query (Connection: yourDatabaseConnection, SQL: item)

Hi @Smitesh_Aher2

Hope the below video will helps!!

Cheers!!

Hi,

you can follow below steps:

  1. Read SQL File:
    Use the “Read Text File” activity to read the content of the SQL file into a string variable.

2.Split Queries:
Split the content of the file into individual queries.
queriesArray = sqlFileContent.Split({“;”}, StringSplitOptions.RemoveEmptyEntries)

3.Database Connection:
Establish a database connection using the “Connect” activity

4.Use a “For Each” activity to iterate through the array of queries.
For Each query In queriesArray
Try
Execute Non Query (using query as SQL command)
Catch (Exception)
Log or handle the exception
End Try

5.Disconnect Database