Skip to main content

Connect

Establishes a connection to a Microsoft SQL Server database.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Credentials - The SQL Server database credentials containing server, port, database, username, and password. Use a Database credential (Category 5) from the vault.

Options

  • None

Output

  • Connection Id - A unique identifier for the established database connection. Store this value to use in subsequent SQL Server operations.

How It Works

The Connect node establishes a connection to a Microsoft SQL Server database using the provided credentials. When executed, the node:

  1. Validates the provided database credentials
  2. Extracts server, port, database, username, and password from the credential
  3. Constructs a SQL Server connection string with the format: User Id={username};Password={password};Database={database};Data Source={server},{port}
  4. Creates and opens a new SqlConnection
  5. Generates a unique connection ID (GUID)
  6. Stores the connection in an internal connections dictionary
  7. Returns the connection ID as output

Requirements

  • Valid SQL Server database credentials with the following fields:
    • server - Hostname or IP address of the SQL Server instance
    • port - Port number (default: 1433)
    • database - Database name (optional, can connect to default database)
    • username - SQL Server username (required)
    • password - SQL Server password
  • SQL Server must be accessible from the robot
  • Proper network connectivity and firewall rules
  • SQL Server Authentication must be enabled (not Windows Authentication)

Error Handling

The node will return specific errors in the following cases:

  • ErrInvalidArg - Database credentials are required, or server hostname is missing
  • ErrConnection - Cannot connect to SQL Server (invalid credentials, server not reachable, network issues)

Usage Examples

Basic Connection

// Store the connection ID from the Connect node output
const connId = $item.conn_id;

// Use this connection ID in subsequent Query, Insert, etc. nodes

Connection with Custom Port

Configure your Database credential with:

  • Server: sql-server.example.com
  • Port: 1434
  • Database: ProductionDB
  • Username: automation_user
  • Password: secure_password

Connection to SQL Server Express

For local SQL Server Express instances:

  • Server: localhost\SQLEXPRESS
  • Port: 1433
  • Database: MyDatabase
  • Username: sa
  • Password: your_password

Connection to Azure SQL Database

For Azure SQL Database:

  • Server: myserver.database.windows.net
  • Port: 1433
  • Database: mydatabase
  • Username: adminuser@myserver
  • Password: your_password

Common Use Cases

  1. Business Intelligence - Connect to SQL Server data warehouses for reporting and analytics
  2. Enterprise Applications - Integrate with ERP, CRM systems using SQL Server
  3. Data Migration - Move data to/from SQL Server databases
  4. Automated Reporting - Extract data from SQL Server for automated reports
  5. Database Maintenance - Automate SQL Server maintenance tasks
  6. Web Application Integration - Connect to SQL Server backends for automation
  7. ETL Processes - Extract, transform, and load data from SQL Server

Tips for Effective Use

  • Store Connection ID - Always store the connection ID in a variable for reuse across multiple database operations
  • Use Vault Credentials - Never hardcode database credentials; use the vault's Database credential type
  • Connection Pooling - Reuse the same connection ID for multiple operations to improve performance
  • Proper Cleanup - Always use the Disconnect node at the end of your flow to close connections
  • Error Handling - Wrap database operations in Try-Catch blocks to handle connection failures gracefully
  • Named Instances - For SQL Server named instances, use format: servername\instancename
  • Connection Timeout - SQL Server connections have a default timeout; ensure server is responsive
  • SQL Authentication - Use SQL Server Authentication mode, not Windows Authentication

Common Errors and Solutions

Cannot Connect to SQL Server

Error: ErrConnection: Cannot connect to SQL Server

Solutions:

  • Verify SQL Server is running and accessible
  • Check server hostname/IP address is correct
  • Ensure the port number is correct (default: 1433)
  • Verify firewall rules allow connections on SQL Server port
  • Check SQL Server is configured to allow remote connections
  • Enable TCP/IP protocol in SQL Server Configuration Manager
  • Verify SQL Server Authentication is enabled (not Windows-only)
  • Test connection using SQL Server Management Studio (SSMS) first
  • For named instances, ensure SQL Server Browser service is running

Missing Credentials Error

Error: ErrInvalidArg: Database credentials are required

Solutions:

  • Select a Database credential from the vault in the Credentials field
  • Ensure the credential contains the required server field

Server Hostname Required

Error: ErrInvalidArg: Server hostname is required in the credential

Solutions:

  • Provide the server hostname or IP address in the credential's server field
  • For named instances, use format: servername\instancename

Login Failed for User

Error: Login failed for user 'username'

Solutions:

  • Verify username and password are correct
  • Ensure SQL Server Authentication mode is enabled
  • Check the SQL Server user exists and is not disabled
  • Verify the user has CONNECT permission to the database
  • For Azure SQL, ensure firewall rules allow your IP address

Error: A network-related or instance-specific error occurred

Solutions:

  • Check SQL Server instance name is correct (e.g., .\SQLEXPRESS)
  • Verify SQL Server Browser service is running (for named instances)
  • Enable TCP/IP in SQL Server Configuration Manager
  • Check Windows Firewall is not blocking SQL Server port
  • Verify SQL Server is configured to listen on TCP/IP

Connection String Details

The node constructs a connection string with these components:

  • User Id={username} - SQL Server login username
  • Password={password} - SQL Server login password
  • Database={database} - Initial database to connect to
  • Data Source={server},{port} - Server address and port

Example connection string:

User Id=appuser;Password=secret123;Database=MyDB;Data Source=sql01.company.com,1433

SQL Server Versions

This package is compatible with:

  • SQL Server 2012 and later
  • SQL Server Express editions
  • Azure SQL Database
  • Azure SQL Managed Instance

Security Considerations

  • Use Strong Passwords - Ensure SQL Server accounts use strong, unique passwords
  • Principle of Least Privilege - Grant only necessary permissions to automation accounts
  • Secure Credentials - Always store credentials in the Robomotion vault
  • Network Security - Use firewalls to restrict database access to authorized IPs
  • Encryption - Consider enabling encrypted connections for sensitive data
  • Audit Logging - Enable SQL Server audit logging for automation accounts
  • Regular Updates - Keep SQL Server updated with latest security patches

See Also