Show TOC

Example: Establishing and Closing the Connection to a DatabaseLocate this document in the navigation structure

Context

In this example, you use the connect method (sdb.sql module) and the release method (SapDB_Session class). You establish a connection to an SAP MaxDB database and close it again.

Procedure

  1. Create a Python script sample.py with the following contents:
    # # Import Python modules # -------------------------------------------
    import sys
    import sdb.sql
    
    # # Parse call arguments # -------------------------------------------
    database_user = sys.argv [1]
    database_user_password = sys.argv [2]
    database_name = sys.argv [3]
    
    # # Connect to the database # -------------------------------------------
    session = sdb.sql.connect (database_user, database_user_password, database_name)
    
    # # Close connection to the database # --------------------------------------------
    session.release ()
    							
    						
    					
  2. Call the Python script:

    python sample.py MONA RED DEMODB