[Tutor] The case of the missing close

Isr Gish isrgish at fastem.com
Wed Dec 1 04:04:06 CET 2004


Hi Robert,

-----Original Message-----
   >From: "Robert, Andrew"<ARobert at MFS.com>
   >Sent: 11/30/04 11:05:57 AM
   >To: "tutor at python.org"<tutor at python.org>
   >Subject: [Tutor] The case of the missing close

<snip>

   >The problem is in closing the connection.
   >
   >No matter what I try,  I receive an error stating that the name is not
   >defined.
   >
   >I receive an error such as:
   >
   >Traceback (most recent call last):
   >  File "M:\My
   >Documents\python_code\oracle\maestrodev_oracle_connector.py", line 55,
   >in ?
   >    db_utils.close()
   >AttributeError: 'module' object has no attribute 'close'

The traceback is telling us exactly wats wrong. In the db_utils module you don't have a function called close. Therfore, when you call db_utils.close() it gives you an error.

You probebly have to call close on the connection. But here I realy don't know anything about connections, so i cant help.

All the best,
Isr

   >
   >Does anyone have any ideas on how to properly close the connection?
   >
   >
   >
   >The db_utils module code is a rather short
   >
   >
   >def dbopen(db,uname,passwd):
   >    #
   >    # Import required system modules needed specifically for function
   >    #
   >    import cx_Oracle
   >
   >    #
   >    # Connect to remote database
   >    #   
   >    connection = cx_Oracle.connect(dsn=db,user=uname,password=passwd)
   >  
   >    #
   >    # Return cursor object to calling program
   >    #
   >    return(connection.cursor())
   >
   >
   >The code that calls the db_utils module is
   >
   >#!c:\Python23\python
   >#
   ># File name: maestrodev_oracle_connector.py
   ># Author: Andrew Robert
   ># Date: 11/26/04
   >#
   >#
   ># Modification History
   >#
   ># Version          Programmer                   Description
   ># 1.0               AAR                          Creation
   ># 1.1               AAR                 Shift database opens to called
   >module
   ># 1.2               AAR                 Fixed database link close - now
   >works
   >#
   >#
   ># Note on modules
   >#
   ># The imported db_utils module was designed by AAR to make standard
   >database
   ># routines available to all python programs as callable functions.
   >#
   ># Called functions are prefaced with the module name and then the
   >function
   ># within the module.
   >#
   >
   >
   >import sys,db_utils
   >
   >#
   ># Make connection to Oracle development database and assign to object
   >#
   >
   >print 'Establishing connection to remote database\n'
   >cursobj = db_utils.dbopen('test_d','FOO','foo')
   >
   >#
   ># Formulate sample querry
   >#
   >cursobj.execute('SELECT userid, name, role, desk_phone, pager FROM
   >contacts')
   >
   >#
   ># Extract querry results 
   >#
   >results=cursobj.fetchall()
   >
   >for row in results:
   >    print row
   >
   >#
   ># Break connection to Oracle development database
   >#
   >print '\n\n\nDisconnecting from remote database'
   >
   >db_utils.close()
   >
   >raw_input("\n\n\t\tPress Enter To Continue")
   >
   >
   >Any help you can provide on this would be greatly appreciated.
   >
   >
   >
   >
   >Thank you,
   >Andrew Robert
   >Systems Architect
   >Information Technology 
   >Massachusetts Financial Services
   >Phone:  617-954-5882
   >Pager:   781-764-7321
   >E-mail:  arobert at mfs.com
   >Linux User Number: #201204
   >
   >
   >"MFS Relay Service" made the following
   > annotations on 11/30/2004 11:11:35 AM
   >------------------------------------------------------------------------------
   >This email communication and any attachments may contain proprietary, confidential, or privileged information.  If you are not the intended recipient, you are hereby notified that you have received this email in error and that any review, disclosure, dissemination, distribution or copying of it or its contents is prohibited.  The sender does not waive confidentiality or any privilege by mistransmission.  If you have received this email in error, please notify the sender immediately, delete this email, and destroy all copies and any attachments.
   >==============================================================================
   >
   >_______________________________________________
   >Tutor maillist  -  Tutor at python.org
   >http://mail.python.org/mailman/listinfo/tutor
   >



More information about the Tutor mailing list