Reputation: 454
I am trying to connect to SAP HANA data source via Python code. I did manage to establish a connection. I have a raw data string in my code as follows:
db = pyodbc.connect(driver = '{HDBODBC}', UID='username', PWD='password', SERVERNODE='server:<port_no>')
However, I do not want the UID and PWD fields in my string. I did set up a DSN connection using the ODBC manager on Windows. But, I still need to enter my username and pwd as follows:
db = pyodbc.connect(DSN="MyDSN", UID='username', PWD='password')
How can I set up a connection without my UID and PWD being displayed in the python code?
Upvotes: 1
Views: 3075
Reputation: 11
Be carefull with parameter CONNECTTIMEOUT=5.
from hdbcli import dbapi
conn = dbapi.connect(key='hdbuserstore key',CONNECTTIMEOUT=5)
This means NOT 5 second because it is in ms. Toke me long time to find out this problem.
Upvotes: 1
Reputation: 146
I have been looking for the same option to use hdbuserstore key to be used with python for connecting to SAP HANA. Looks like HDB client hdbcli has that option added now.
The user that is running the script needs to have the PYTHON_PATH set to the location of the hdbclient
or in the script you can have the path set.
from hdbcli import dbapi
conn = dbapi.connect(key='hdbuserstore key',CONNECTTIMEOUT=5)
conn.isconnected()
will return True if the connection is successful.
hope this is helpful for someone!
Upvotes: 2
Reputation: 10396
This requirement is relatively easy to fulfill.
The SAP HANA client software (the package that also contains the ODBC driver) provides a program to set up a secure store for logon data: hdbuserstore
.
In my blog I explained how that works in detail.
The core steps are
create the hdbuserstore
entries for the operating system user that should use the application.
Syntax: hdbuserstore SET <KEY> <ENV> <USERNAME> <PASSWORD>
Example: hdbuserstore SET millerj "localhost:30115" JohnMiller 2wsx$RFV
The hdbuserstore
key needs to be referred to in the ODBC connection.
To do that, fill the SERVERNODE
parameter with @<KEYNAME>
instead of the actual server address.
For the example above, the value would be @millerj
.
And that's really all. The ODBC driver will try to look up the hdbuserstore
entry provided upon connection and use that to connect to the database.
Check the documentation for more information on this.
Upvotes: 0
Reputation: 1675
for example create file in a secure place and load connection setting (UID, PWD encrypted password (heshkod)) from this file
Upvotes: 0