DBConnection Data Type

Official Content
This documentation is valid for:

Allows the configuration options for the connections to the database to be determined in execution time.


In order to be able to modify the configuration options of the different data stores, from a GeneXus object and in execution time, a DBConnection data type variable must be defined. To do this, you associate this variable with a specific connection (a GeneXus data store) using the GetDataStore function, and then you manage this connection using the available properties and methods.


  • In Web Environments only applies using Before Connect property.  
    Database connections in Web objects are handled using a pool, so is not allowed to change it at runtime. Therefore it can only be used within the Procedure referenced in the previous property.
  • For Command Line Procedures it must be taken into account that the Connect()/Disconnect() methods close the cursors which are opened in the connection they apply to. Because of this, it is not possible to execute the Connect() and/or Disconnect() method within the scope of a For each command. The developer is responsible for using the connection/disconnection at the right moment. E.g.: if the disconnection is done in the middle of a procedure, the execution may be canceled. There is also the possibility of continuing working if the procedure is reconnected, but the results will be unpredictable.



Important: If the Before Connect property is set, the Connect() method execute that procedure, except when it is referenced within that object.


  • ODBC Connection
    &MyConnection is a variable of DBConnection type
    &MyConnection = GetDatastore(!"default")
    &MyConnection.UserName = !"Administrator"
    &MyConnection.UserPassword = !"Adm!Password"
    &MyConnection.ShowPrompt = 2

  • JDBC Connection

&MyConn is a variable of DBConnection type

Event 'Connect'
      &myConn = GetDataStore(!"Default")
      &myConn.UserName = trim(&User)
      &myConn.UserPassword = trim(&Password)
      &myConn.ShowPrompt = 2
      &Res = &myConn.Connect()
      Do case
        Case &Res = 0
              &ConnOk = !'Y'
              &ConnOk = !'N'
              msg('Unsuccessful connection, retry...')
EndEvent  // 'Connect'


Objects: Procedures, Transactions, Web Panels
Languages: .Net, Java

Security Tips

-Avoid setting external user's data to the properties or methods, or sanitize accordingly the entries

See Also

GetDataStore Function