Connect to database

I have downloaded Databse library as well as pymssql module to connect to db that is used company wide.

I receiving below error with the code used

<[FAIL (+0.23s)] OperationalError: (18456, b"Login failed for user ‘FORDVRANA4’.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (phy310082l.pp.f01.dc1.ford.com)\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (phy310082l.pp.f01.dc1.ford.com)\n")
Validate DB | FAIL |
OperationalError: (18456, b"Login failed for user ‘FORDVRANA4’.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (phy310082l.pp.f01.dc1.ford.com)\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (phy310082l.pp.f01.dc1.ford.com)\n")>


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

*** Variables ***
${DBName}       DBname(used actual name in my code)
${DBUser}       Username(used actual name in my code)
${DBPassword}   None
${DBServer}     servername(used actual name in my code)
${DBPort}       1433


*** Test Cases ***
Validate DB
  Connect DB
  Disconnect From Database


*** Keywords ***
Connect DB
  Connect To Database     pymssql     ${DBName}   ${DBUser}   ${DBPassword}   ${DBServer}   ${DBPort}

any help is appreciated .
Thank in advance.

Hi Vinay,

This is usually either

  • Incorrect user name / password combination
  • User doesn’t have permissions to the related database

Also

What did the messages from the SQL Server say? what was the text for error message 20002?

This will should give you a pretty good idea as to what the actualy issue is :crossed_fingers:

Dave.

1 Like

It looks like your code is probably working fine, but the account or connection method is incorrect then…If you’re on Windows, there’s a really old & largely unknown tip to help test a database connection outside of any code…

  1. Create a new file.txt
  2. Rename the extension to file.udl
  3. Double-click the file to open it
  4. Fill out the GUI screen & keep hitting test connection until you get a success
  5. Rename the file back to file.txt
  6. Open this file & ta-da… it’s got a connection string for you to use! :c)
1 Like

It might be on the SQL Server end… for example, some of these etc.

  1. Your account is disabled in SQL server
  2. Your account has not been added to that SQL server
  3. Your account in SQL Server is not assigned to/allowed to access the database you’re trying to access
  4. You’re using a username/password combination but the SQL Server only accepts Windows Authentication/SSPI (or visa-versa)
1 Like