Connect to Oracle database using pyodbc
<p>I would like to connect to an Oracle database with python through pyodbc. I have installed oracle driver and I tried the following script:</p>

<pre><code>import pyodbc
connectString = """
                DRIVER={Oracle in OraClient12Home1};
                SERVER=some_oracle_db.com:1521;
                SID=oracle_test;
                UID=user_name;
                PWD=user_pass
                """
cnxn = pyodbc.connect(connectString)
</code></pre>

<p>I got the following error message:</p>

<pre><code>cnxn = pyodbc.connect(connectString)

Error: ('HY000', '[HY000] [Oracle][ODBC][Ora]ORA-12560: TNS:protocol adapter error\n (12560) (SQLDriverConnect)')
</code></pre>

<p>What's wrong here?</p>

<p>Looks Like your missing a PORT</p>

<p>Try this way</p>

<p><strong>NOTE:</strong>
Depending on your Server the syntax can be different this will work for Windows without DSN using an SQL Server Driver.</p>

<pre><code>connectString = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;PORT=1433;DATABASE=testdb;UID=me;PWD=pass')
</code></pre>

<p>This is the connection, you still need a cursor and to use execute along with an SQL Statement..  </p>

python oracle