Re: cx_Oracle.DatabaseError: ORA-12505: TNS:listener does not currently know of SID given in connect descriptor

  • From: Craig Hagan <hagan@xxxxxxx>
  • To: jose.soares@xxxxxxxxxxxxxx
  • Date: Wed, 14 Dec 2011 09:20:39 -0500

it would help greatly if you provide a few additional things:
1) the listener configuration file
2) what dsn gets evaluated to

However, I'm pretty sure that the problem is that you're depending upon
service
names for your connection to succeed (that should be how the url in your
working example behaves), but the dsn you're constructing via make_dsn is
specifying SID= which is failing your connection.

A possible simple solutions for you would be to either

1) write your own equivalent of makedsn, which really ought not be too
hard. You'd want to emit something like this:

(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=your-db-hostname)(PORT=yourport)))(CONNECT_DATA=(SERVICE_NAME=your-service-name)))

vs. what makedsn emits, which is stuff like this:
(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=your-db-hostname)(PORT=yourport)))(CONNECT_DATA=(SID=your-dbname)))

2) use tnsnames, which would then let you avoid generating the dsn in
software

-- craig

On Tue, Dec 13, 2011 at 11:39 AM, jose soares <jose.soares@xxxxxxxxxxxxxx>wrote:

> Hi all,
>
> I'm trying to connect to a server oracle using cx_Oracle and I get the
> error:
>
> cx_Oracle.DatabaseError: ORA-12505: TNS:listener does not currently know
> of SID given in connect descriptor
>
> Here my code:
>
> def init_db_conn(parms):
>    global _CONN
>    import cx_Oracle
>    dsn = cx_Oracle.makedsn(parms['host'],parms['port'],parms['dbname'])
>    dbinfo = 'db: %s@%s' % (parms['user'], parms['dbname'])
>    try:
>        if not _CONN:
>            _CONN = cx_Oracle.connect(parms['user'], parms['password'], dsn)
>    except:
>        ex = sys.exc_info()
>        s = 'Exception: %s: %s\n%s' % (ex[0], ex[1], dbinfo)
>        print s
>        return None
>    return _CONN
>
>
>
> if I use instead the following code it works:
>
> conn = 'myusername/Sf3r4c4rt4@xxxxxxxxxxxx:1521/SHELL'
> cc = cx.connect(conn)
> print cc.version
> cc.close()
>
> What's wrong with the first function where I use makedsn?
>
>
> thanks for any help.
> j
>
>
>
>
> --
> //www.freelists.org/webpage/oracle-l
>
>
>


-- 
          .-    ... . -.-. .-. . -    -- . ... ... .- --. .

                            Craig I. Hagan
                           hagan(at)cih.com

"If you aren't getting something for nothing, you're not getting your fair
share."
           - Huey Long


--
//www.freelists.org/webpage/oracle-l


Other related posts: