Procedure documentationExample: Establishing and Closing the Connection to a Database Locate this document in the navigation structure

 

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

Procedure

  1. Create a Python script sample.py with the following contents:

    Syntax Syntax

    1. #
      # 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 ()
      
    End of the code.
  2. Call the Python script:

    python sample.py MONA RED DEMODB