How to work with CSV files using Database block?

How to work with CSV files using Database block?

Users can work with CSV files through Leapwork using the ODBC driver. Below are the steps to configure ODBC Driver for Database.

Prerequisite:

In order to work with CSV files in Leapwork using Database block, 32/64 bit ODBC needs to be present on the user's machine depending upon the operating system.

Please install ODBC 64-bit AccessDatabaseEngine_X64.exe from here.

Configure ODBC:

  1. Open the 64-bit ODBC application in your system.

  2. Click on Add button present in "User DSN".

  3. Select "Microsoft Access Text Driver (.txt,.csv)" (as shown below) and click Finish.

  4. Enter a logical name for the ODBC data source,

    1. "Data Source Name" is used in the database block as "Connection" while accessing the database from Leapwork,
    2. Enter a meaningful description.
    3. Now remove the checkbox present in front of "Use Current Directory", and then click on "Select Directory".
  5. Navigate to the folder/directory where your CSV file is present. Select the file and then click on "OK".

  6. Click "OK" and close the ODBC Text Setup.

  7. After successful configuration, the Data Source for the CSV file created can be seen under the Name in ODBC Data Source Administrator. Click "OK" and close the ODBC Data Source Administrator.

Note: If you choose this option then "Connection" in Leapwork database block should be defined as “ TestingCsv” (as defined in step no 4 above. Please remember there should be no spaces in, before, and after the connection string).

Working On CSV Data from Studio:

Open Leapwork Studio, add a Database block, put the Connection name, add a valid query, and click on the Refresh button. If the configuration is successful, the Database block will show the column names present in the CSV file.

Example: For the above connection that we have configured, the Connection name will be "Testingcsv".

Query to "Read" the contents present in the CSV files will be: SELECT * FROM "survey.csv";

For any clarification, please contact our Priority Support.