Hi, I'm facing issue while connecting the robot framework to SQL server database, Could you please help me to clear this issue

SQL server image

Actual Code:
*** Settings ***
Library DatabaseLibrary
Library OperatingSystem
Library SeleniumLibrary
Library Telnet

Suite Setup Connect To Database pymysql ${dbName} ${dbUsername} ${dbPassword} ${dbHost} ${dbPort}
Suite Teardown Disconnect From Database

*** Variables ***
${dbName} SQL Server(MSSQLSERVER)
${dbUsername} Empty
${dbPassword} Empty
${dbHost} DESKTOP-K60PBIF
${dbPort} 1433

*** Test Cases ***
Create Person Table
${output}= Execute Sql String Create Table person(id integer,first_name varchar(20),last_name varchar(20));
Log To Console ${output}
Should Be Equal As Strings ${output} None

Error message:
dbTesting1 | FAIL |
Suite setup failed:
OperationalError: (2003, “Can’t connect to MySQL server on ‘DESKTOP-K60PBIF’ ([WinError 10061] No connection could be made because the target machine actively refused it)”)

Also suite teardown failed:
AttributeError: ‘NoneType’ object has no attribute ‘close’

1 test, 0 passed, 1 failed

You are using the MySQL driver to attempt to connect to a Microsoft SQL Server.
Use the correct driver :slight_smile:

1 Like

Hi Helio, Thanks for your reply.

But still I’m facing the below issues, Could you please help me to solve this one.

*** Settings ***
Library DatabaseLibrary
Library OperatingSystem
Library SeleniumLibrary
Library Telnet

Suite Setup Connect To Database pymssql ${dbName} ${dbUsername} ${dbPassword} ${dbHost} ${dbPort}
Suite Teardown Disconnect From Database

*** Variables ***
${dbName} MS
${dbUsername} Empty
${dbPassword} Empty
${dbHost} 192.168.1.3
${dbPort} 1433

*** Test Cases ***
Create Person Table
${output}= Execute Sql String Create Table person(id integer,first_name varchar(20),last_name varchar(20));
Log To Console ${output}
Should Be Equal As Strings ${output} None

Error message - output:

Create Person Table | FAIL |
Parent suite setup failed:
OperationalError: (18456, b"Login failed for user ‘Empty’.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 2
0002, severity 9:\nAdaptive Server connection failed (192.168.1.3)\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (192.168.1.3)\n")

dbTesting1 | FAIL |
Suite setup failed:
OperationalError: (18456, b"Login failed for user ‘Empty’.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 2
0002, severity 9:\nAdaptive Server connection failed (192.168.1.3)\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (192.168.1.3)\n")

Also suite teardown failed:
AttributeError: ‘NoneType’ object has no attribute ‘close’

1 test, 0 passed, 1 failed

This is telling you that the password “Empty” is not valid for database user “Empty”

Are you sure these values are correct? Is “Empty” really the database userid and is “Empty” really Empty’s password?

No need to worry about this error for now, you can’t disconnect from the database if you weren’t connected in the first place.

Dave.

1 Like

Hi @damies13 damies13, @HelioGuilherme66

Thanks for your reply, But I’m still facing the issue and unable to connect to the DB server.

I got a message from a friend,
This seems to be an issue with Firewall access. Please check with developer or IT team to open up the firewall access for the given port number.

How we can approach the firewall access. What are the settings we have to do to overcome this.

Please help me out :frowning:

Thanks

Hi Dinesh,

If indeed it’s a firewall issue (nothing in your posts proves it is or isn’t) then there is nothing you can do, no setting you can change in robot framework that will change the firewall. As your friend advised you will need to get someone who can administer the firewall to make that change for you:

You can however test to see if it’s a firewall issue, you can run “Microsoft SQL server studio” (See the screen shot in your original post) on the same machine as you are running robot framework. if SQL Studio is able to connect from this machine to the database then it’s not a firewall issue, and that will also let you confirm if the user Empty with the password Empty is the correct username and password?

If you get a message about incorrect username or password, that would also indicate that it’s not a firewall issue but simply a user/password issue, try with a different username password, preferably one the DBA knows is working.

Dave.