RobotFramework - Connecting to SQL SERVER integrated windows logon

1.5k Views Asked by At

I was trying to connect to the SQL Server 2012 database using the robot framework for a long time unsuccessfully, finally came up with this

*** Settings ***

Test Setup   Connect To Database Using Custom Params 
   pymssql     ${server},${username},${password},${databasename},${trusted}

all in a single line with tab spaces inbetween

Where Test Setup - Is the key word used under Settings for setting up the DB Environment in this case Connect To Database Using Custom Params -- are the keywords to connect to database which are found in the databaselibrary of RobotFramework pymssql - Module for connecting with SQLSERVER database

The below are the parameters to be passed

  1. server - name of the server in single quote
  2. username - Username along with the domain name - format - 'domain-name\username'
  3. Password - self explanatory
  4. Trusted - The value should be set as 'True'

This helped me in establishing the connection with sql server 2012, but i still face issues.

Error message Setup failed: SyntaxError: EOL while scanning string literal (, line 1)

2

There are 2 best solutions below

0
Tony81 On

I know this is a bit old, but I was looking for the answer to the same problem and worked out that it should be the following

Test Setup   Connect To Database Using Custom Params 
   pymssql     '${server}','${username}','${password}','${databasename}','${trusted}'

pymsql requires the commas between the variables to identify each separate part. RF passes the whole thing a one long string to pymssql by putting the ' around each variable it is clearly identified as a separate connection setting by pymssql.

This worked for me when I wanted to connect to a server and run queries on several different databases at the same time

Connect To Database Using Custom Params    pymssql    '${server}','${username}','${password}'

I can then use the database name in the query or execution string

0
Vivek Kulkarni On

In Robotframework if you want to work with SQL Server. Down load pyodbc package. Add Library to the testcase. Then write query to execute. Below is the sample code

*** Settings *** Library DatabaseLibrary Library OperatingSystem Library pyodbc