Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

sql server - Issue with RobotFramwork Connect To Database Using Custom Params

Getting Below Error OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (53)'

    *** Settings ***
Documentation     Simple example using DBLibrary.
Library           SeleniumLibrary
Library           DatabaseLibrary 
*** Variables ***
${DBHost_ConnectionString}  'DRIVER={SQL Server};SERVER="hostname";UID="uname";PWD="******";DATABASE="dbname"'   

*** Test Cases ***

Connect Database
    Connect To Database Using Custom Params    pyodbc    ${DBHost_ConnectionString}

I tried all the solutions over internet, like adding port to connection string, appending tcp before servername, e.t.c, Followed the implementation mentioned in the source code of dbapi https://github.com/franz-see/Robotframework-Database-Library/blob/master/src/DatabaseLibrary/connection_manager.py

 elif dbapiModuleName in ["pyodbc", "pypyodbc"]:
            dbPort = dbPort or 1433
            logger.info('Connecting using : %s.connect(DRIVER={SQL Server};SERVER=%s,%s;DATABASE=%s;UID=%s;PWD=%s)' % (dbapiModuleName, dbHost, dbPort, dbName, dbUsername, dbPassword))
            self._dbconnection = db_api_2.connect('DRIVER={SQL Server};SERVER=%s,%s;DATABASE=%s;UID=%s;PWD=%s' % (dbHost, dbPort, dbName, dbUsername, dbPassword))

Any help should be appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As a guess, you shouldn't surround your connection string with single quotes, as they become part of the connection string. Robot is not python, and robot is not the shell, so you don't normally need to quote strings.

*** Variables ***
${DBHost_ConnectionString}  DRIVER={SQL Server};SERVER="hostname";UID="uname";PWD="******";DATABASE="dbname"

It's not clear if you're literally using the string hostname and uname, etc., or if that's just boilerplate for the purpose of the question. You need to be passing the actual hostname and actual username and password.

You may not need the quotes around the other values, in which case it would look like this:

*** Variables ***
${DBHost_ConnectionString}  DRIVER={SQL Server};SERVER=hostname;UID=uname;PWD=******;DATABASE=dbname

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...