Robot Framework连接公司SQL Server数据库失败求助
已安装Robot Framework的DatabaseLibrary库及pymssql模块,尝试连接公司SQL Server数据库时出现登录失败及连接错误,错误信息如下:
[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")
使用的Robot Framework代码如下:
*** 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}
- 修正密码参数:代码中
${DBPassword}设为None,pymssql对空密码的处理需传空字符串""而非None;若账号实际有密码,替换为真实密码。 - 确认身份验证模式:
- 若使用SQL Server身份验证,确保账号
FORDVRANA4是SQL Server登录名,而非Windows域账号; - 若为域账号,改用Windows集成认证,无需传入用户名密码,连接语句修改为:
Connect To Database pymssql ${DBName} server=${DBServer}:${DBPort} trusted_connection=yes
- 若使用SQL Server身份验证,确保账号
- 检查服务器连通性:
- 验证服务器地址
${DBServer}是否正确,确认本地能ping通该服务器; - 用
telnet ${DBServer} ${DBPort}测试端口1433是否开放,若不通联系IT确认防火墙规则或端口配置。
- 验证服务器地址
- 验证账号权限:
- 确认
FORDVRANA4账号在SQL Server中存在且未被禁用; - 检查该账号是否拥有目标数据库
${DBName}的访问权限。
- 确认
- 版本兼容性尝试:若上述步骤无效,升级pymssql到最新稳定版,或替换为pyodbc模块连接(DatabaseLibrary同样支持),示例语句:
Connect To Database pyodbc DRIVER={ODBC Driver 17 for SQL Server};SERVER=${DBServer},${DBPort};DATABASE=${DBName};UID=${DBUser};PWD=${DBPassword}
内容的提问来源于stack exchange,提问作者vinay rana

