Connect to SQL Server

Connects to an SQL Server database.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

Establishes a connection woth an SQL Server database.

Dependencies

You need a valid connection string to connect to the SQL Server database. See the connectionstring parameter for examples of valid connection strings.

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in RPA Studio's Script mode.

sqlServerConnect --connectionstring(String) (DbConnection)=connection

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Connection String connectionstring Required Text The connection string to connect to the SQL Server Database.

See the connectionstring parameter section for details.

connectionstring parameter

The connectionstring parameter is where you enter the string that includes key-value pairs providing the necessary information to connect to the SQL Server database. The following code block is an example of a valid connection string:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
  • Server: The address or hostname of the SQL Server.
  • Database: The name of the specific database that you want to connect to.
  • User Id: Specifies the username for authentication.
  • Password: Specifies the password for authentication.

Replace each field with your actual SQL database server credentials and connection details.

Output parameters

Designer mode label Script mode name Accepted variable types Description
Connection connection Database Connection Returns the data from the database connection.

Example

This example connects to an SQL Server database by using the Assert Condition (assert) command to verify whether the connection was successful. The message "Could not connect to the Database!" is displayed if the connection is empty.

defVar --name connection --type DbConnection
// Connect to the database via the connection string and store the connection data in the connection variable.
sqlServerConnect --connectionstring "Server=myServerAddress;Database=myDataBase;User Id=myUsername;\r\nPassword=myPassword;" connection=connection
// Check if the connection was successful
assert --message "Could not connect to the Database!" --left "${connection}" --operator "Is_Null" --negate