2

I am trying to connect an oracle database from my python code using pypyodbc:

conn_string = "driver={Oracle in OraClient11g_home1}; server='example.oneco.com:1521'; database='tabto'; uid='myuid'; pwd='mypwd'"
conn = pypyodbc.connect(conn_string)

I got error message:

Error: (u'HY000', u'[HY000] [Oracle][ODBC][Ora]ORA-12560: TNS:protocol adapter error\n')

Following is the connection string found in my tnsnames.ora file. Please tell me what is the right way to use pypyodbc.

tabto, tabto.world, tabto.oracleoutsourcing.com, tabto.oneco.com =
  (DESCRIPTION =
    (ADDRESS = 
      (PROTOCOL = TCP)
      (HOST = example.oneco.com)
      (PORT = 1521)
    )
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = tabto_dcu)
    )
  )
1
  • The key is to link python code to tnsname.ora by define dbq parameter. So change the code to the following worked. conn_string = "driver={Oracle in OraClient11g_home1}; dbq='tabto'; uid='myuid'; pwd='mypwd'" conn = pypyodbc.connect(conn_string) Commented Jan 5, 2017 at 16:36

2 Answers 2

3

The key is link python code to tnsname.ora by defining dbq parameter. So change the code to the following worked.

conn_string = "driver={Oracle in OraClient11g_home1}; dbq='tabto'; uid='myuid'; pwd='mypwd'"
conn = pypyodbc.connect(conn_string)
Sign up to request clarification or add additional context in comments.

1 Comment

I just want to clarify for future references, as I got confused about this. But the parameter for dbq can be any of the tns names specified. So dbq='tabto.oneco.com' or dbq='tabto.world' would work also.
0
conn = pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};SERVER=example.oneco.com:1521;DATABASE=tabto;UID=youruid;PWD=password')

try it without quotes(') of your code in the middle...

check too pyodbc wiki: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Windows

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.