parameters: (connection, password)
return_statement: return 1
docstring: Establishes a connection to the server and stores the connection object in the connections pool.
  
      It first looks for a connection with the given connection parameters in the connections pool to
      reuse existent connections. If such connection is found it queries the server to ensure that the
      connection is alive and reestablishes it if is dead. If no suitable connection is found in the
      connections pool, a new one is created and stored in the pool.
  
      Parameters:
      ===========
          connection:  an object of the class db_mgmt_Connection storing the parameters
                       for the connection.
          password:    a string with the password to use for the connection.
docstring_summary: Establishes a connection to the server and stores the connection object in the connections pool.
docstring_tokens: Establishes a connection to the server and stores the connection object in the connections pool .
function: def connect(connection, password):
      '''Establishes a connection to the server and stores the connection object in the connections pool.
  
      It first looks for a connection with the given connection parameters in the connections pool to
      reuse existent connections. If such connection is found it queries the server to ensure that the
      connection is alive and reestablishes it if is dead. If no suitable connection is found in the
      connections pool, a new one is created and stored in the pool.
  
      Parameters:
      ===========
          connection:  an object of the class db_mgmt_Connection storing the parameters
                       for the connection.
          password:    a string with the password to use for the connection.
      '''
      con = None
      try:
          con = get_connection(connection)
          try:
              if not con.cursor().execute('SELECT 1'):
                  raise Exception("connection error")
          except Exception as exc:
              grt.send_info("Connection to %s apparently lost, reconnecting..." % connection.hostIdentifier)
              raise NotConnectedError("Connection error")
      except NotConnectedError as exc:
          host_identifier = connection.hostIdentifier
          version = ""
          grt.send_info("Connecting to %s..." % host_identifier)        
          import pyodbc
          try:
              con = db_driver.connect(connection, password)
              
              # Adds data type conversion functions for pyodbc
              if connection.driver.driverLibraryName == 'pyodbc':
                  version = con.execute("SELECT CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR)").fetchone()[0]
                  majorVersion = int(version.split('.', 1)[0])
                  if majorVersion >= 9:
                      con.add_output_converter(-150, lambda value: value if value is None else value.decode('utf-16'))
                      con.add_output_converter(0, lambda value: value if value is None else value.decode('utf-16'))
                  else:
                      con.add_output_converter(-150, lambda value: value if value is None else str(value))
                      con.add_output_converter(0, lambda value: value if value is None else str(value))
  
          except pyodbc.Error as odbc_err:
              # 28000 is from native SQL Server driver... 42000 seems to be from FreeTDS
              if len(odbc_err.args) == 2 and odbc_err.args[0] in ('28000', '42000') and "(18456)" in odbc_err.args[1]:
                  raise grt.DBLoginError(odbc_err.args[1])
  
          if not con:
              grt.send_error('Connection failed', str(exc))
              raise
          grt.send_info("Connected to %s, %s" % (host_identifier, version))
          
          _connections[connection.__id__] = {"connection" : con }
          _connections[connection.__id__]["version"] = getServerVersion(connection)
      return 1
function_tokens: def connect ( connection , password ) : con = None try : con = get_connection ( connection ) try : if not con . cursor ( ) . execute ( 'SELECT 1' ) : raise Exception ( "connection error" ) except Exception as exc : grt . send_info ( "Connection to %s apparently lost, reconnecting..." % connection . hostIdentifier ) raise NotConnectedError ( "Connection error" ) except NotConnectedError as exc : host_identifier = connection . hostIdentifier version = "" grt . send_info ( "Connecting to %s..." % host_identifier ) import pyodbc try : con = db_driver . connect ( connection , password ) # Adds data type conversion functions for pyodbc if connection . driver . driverLibraryName == 'pyodbc' : version = con . execute ( "SELECT CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR)" ) . fetchone ( ) [ 0 ] majorVersion = int ( version . split ( '.' , 1 ) [ 0 ] ) if majorVersion >= 9 : con . add_output_converter ( - 150 , lambda value : value if value is None else value . decode ( 'utf-16' ) ) con . add_output_converter ( 0 , lambda value : value if value is None else value . decode ( 'utf-16' ) ) else : con . add_output_converter ( - 150 , lambda value : value if value is None else str ( value ) ) con . add_output_converter ( 0 , lambda value : value if value is None else str ( value ) ) except pyodbc . Error as odbc_err : # 28000 is from native SQL Server driver... 42000 seems to be from FreeTDS if len ( odbc_err . args ) == 2 and odbc_err . args [ 0 ] in ( '28000' , '42000' ) and "(18456)" in odbc_err . args [ 1 ] : raise grt . DBLoginError ( odbc_err . args [ 1 ] ) if not con : grt . send_error ( 'Connection failed' , str ( exc ) ) raise grt . send_info ( "Connected to %s, %s" % ( host_identifier , version ) ) _connections [ connection . __id__ ] = { "connection" : con } _connections [ connection . __id__ ] [ "version" ] = getServerVersion ( connection ) return 1