Database actions
To connect to a database, use the Open SQL connection action. A connection string specifies all information necessary to connect to a database, such as the driver, the database, server names, and the username and password.
The following connection string connects to an Excel database:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myExcelFile.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";
The following connection string connects to an Access database:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb; Persist Security Info=False;
Note
Power Automate for desktop is a 64-bit application, only 64-bit installed drivers are available for selection in the Open SQL connection action.
Configure a connection string manually
To manually build a connection string:
Select Build connections string to open the Data Link Properties dialog. The data link tool helps you compose the required connection string step by step.
Once you access the wizard, select the correct driver for the database under Provider.
Next, under the Connection tab, enter the remaining details such as the server name, the username, password, and database name. Select Test Connection to test that the connection string connects successfully.
Specify a connection timeout and other network settings in the Advanced tab.
Open SQL connection
Open a new connection to a database.
Input parameters
Argument | Optional | Accepts | Default Value | Description |
---|---|---|---|---|
Connection string | No | Text value | The connection string to use to connect to the database |
Variables produced
Argument | Type | Description |
---|---|---|
SQLConnection | SQL connection | A handle for the new SQL connection |
Exceptions
Exception | Description |
---|---|
Can't connect to data source | Indicates a problem connecting to the data source |
Invalid connection string | Indicates that the specified connection string is invalid |
Execute SQL statement
Connect to a database and execute a SQL statement.
To execute an SQL query, use the Execute SQL statement action. Begin by providing a valid connection to the respective database. Select the desired option in the Get connection by property. You can either provide an SQL connection variable (you can create one by using the Open SQL connection action) or by providing the Connection string. Then input the SQL query you want to execute in the SQL statement property. You can also modify the timeout seconds of the action or leave the default option (30 seconds).
Input parameters
Argument | Optional | Accepts | Default Value | Description |
---|---|---|---|---|
Get connection by | N/A | Connection string, [SQL connection variable] | SQL connection variable | Specifies whether to create a new connection from a given connection string or select an already open connection |
SQL connection | No | SQL connection | The handle for the new SQL connection | |
Connection string | No | Text value | The connection string to use to connect to the database | |
SQL statement | No | Text value | The SQL statement to execute to the database | |
Timeout | Yes | Numeric value | 30 | The maximum amount of time to wait for a result from the database |
Variables produced
Argument | Type | Description |
---|---|---|
QueryResult | Datatable | The result from the database in the form of a data table, with rows and columns |
Exceptions
Exception | Description |
---|---|
Can't connect to data source | Indicates a problem connecting to the data source |
Invalid connection string | Indicates that the specified connection string is invalid |
Error in SQL statement | Indicates there's an error in the given SQL statement |
Close SQL connection
Close an open connection to a database.
Input parameters
Argument | Optional | Accepts | Default Value | Description |
---|---|---|---|---|
SQL connection | No | SQL connection | The handle for the new SQL connection |
Variables produced
This action doesn't produce any variables.
Exceptions
This action doesn't include any exceptions.
Feedback
Submit and view feedback for