On Apr 30, 2010, at 3:31 AM, dhanil anupurath wrote: > > import pkg_resources > pkg_resources.require("cx-Oracle>=5.0.3") > import cx_Oracle >
> connstr='<username>/<password>@localhost' > conn = cx_Oracle.connect(connstr) I just want to go over how this is documented. From the cx_oracle documentation at http://cx-oracle.sourceforge.net/html/module.html#cx_Oracle.connect , we see that the above is taken as the format "user/p...@dsn", where "dsn" is the TNS name from your tnsnames.ora file - ideally it would be the string "xe", but it seems to correlate the hostname of "localhost" as well. Onto SQLAlchemy's, the document at http://www.sqlalchemy.org/docs/reference/dialects/oracle.html?highlight=cx_oracle#connecting states : Connecting with create_engine() uses the standard URL approach of oracle://user:p...@host:port/dbname[?key=value&key=value...]. If dbname is present, the host, port, and dbname tokens are converted to a TNS name using the cx_oracle makedsn() function. Otherwise, the host token is taken directly as a TNS name. So the equivalent connect string is: create_engine('oracle://<user>:<password>@localhost') meaning, '/dbname' is not present, so the 'host' portion, in this case 'localhost', is sent to cx_Oracle.connect as the TNS name. The usual way to connect looks like: create_engine('oracle://<user>:<password>@localhost/xe') the advantage to this approach is that SQLAlchemy uses cx_Oracle.makedsn() so that no TNS entry is required. Here are all the ways to connect to a localhost XE server: import cx_Oracle print cx_Oracle.connect('scott/ti...@localhost') print cx_Oracle.connect('scott/ti...@xe') print cx_Oracle.connect('scott', 'tiger', 'localhost') print cx_Oracle.connect('scott', 'tiger', 'xe') print cx_Oracle.connect('scott', 'tiger', cx_Oracle.makedsn('localhost', 1521, 'xe')) from sqlalchemy import create_engine print create_engine('oracle://scott:ti...@localhost').connect().connection.connection print create_engine('oracle://scott:ti...@xe').connect().connection.connection print create_engine('oracle://scott:ti...@localhost/xe').connect().connection.connection output of this looks like: <cx_Oracle.Connection to sc...@localhost> <cx_Oracle.Connection to sc...@xe> <cx_Oracle.Connection to sc...@localhost> <cx_Oracle.Connection to sc...@xe> <cx_Oracle.Connection to scott@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SID=xe)))> <cx_Oracle.Connection to sc...@localhost> <cx_Oracle.Connection to sc...@xe> <cx_Oracle.Connection to scott@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SID=xe)))> note the two forms of connection that use makedsn() have a locally-generated TNS entry present. Also note that SQLAlchemy is not using pkg_resources to import cx_Oracle. It just calls "import cx_Oracle". If the above pkg_resources call is required (extremely unlikely), you need to call it before create_engine(). hope this helps. > # tnsnames.ora Network Configuration File: > > XE = > (DESCRIPTION = > (ADDRESS = (PROTOCOL = TCP)(HOST = > localhost.localdomain)(PORT = 1521)) > CONNECT_DATA = (SID = XE)) > ) > > sqlnet.authentication_services = (NONE) > > LISTENER.ORA > # listener.ora Network Configuration File: > > SID_LIST_LISTENER = > (SID_LIST = > (SID_DESC = > (SID_NAME = PLSExtProc) > (ORACLE_HOME = /usr/lib/oracle/xe/app/ > oracle/product/10.2.0/server) > (PROGRAM = extproc) > ) > (SID_DESC = > (SID_NAME = m...@localhost) > (ORACLE_HOME = /usr/lib/oracle/xe/app/oracle/ > product/10.2.0/server) > ) > ) > > LISTENER = > (DESCRIPTION_LIST = > (DESCRIPTION = > (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE)) > (ADDRESS = (PROTOCOL = TCP)(HOST = > localhost.localdomain)(PORT = 1521)) > ) > ) > > DEFAULT_SERVICE_LISTENER = (XE) > > SQLNET.ORA > This is the uncommented line in the sqlnet.ora > > > > 9.On googling ,I saw someone indicate that sql.authentication should > be set to none. > I did that but no avail. > > I would really appreciate any help in resolving this problem. > > Thanks. > > > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.