Official Content

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

Description

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.

Notes

  • In Web applications, you should only change connection settings in a procedure referenced by the Before Connect property. This is because Database connections in Web applications are handled using a pool. You should not change connection settings in an event of a Web object, or a procedure called by an event of a Web Object.
  • 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, Connect() and/or Disconnect() methods must not be called 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 that afterward requires the connection, the execution may be canceled.

Properties

Methods

Important: If the Before Connect property is set, the Connect() method executes that procedure, except when it is referenced within that object (to avoid an infinite loop).

Example​​​​​

1) Setting a JDBC Connection in a command-line procedure

&MyConn is a variable of DBConnection type

      &myConn = GetDataStore(!"Default")
      &myConn.UserName = trim(&User)
      &myConn.UserPassword = trim(&Password)
      &myConn.JDBCDriverName=!'com.inet.tds.TdsDriver'
      &myConn.JDBCDriverURL=!'jdbc:inetdae:barbanegra:1433?database=testemp2'
      &myConn.ShowPrompt = 2
      &Res = &myConn.Connect()
      Do case
        Case &Res = 0
              &ConnOk = !'Y'
              return
         Otherwise
              &ConnOk = !'N'
              msg('Unsuccessful connection, retry...')
      Endcase

2) Changing connection settings in a procedure referenced by the Before Connect Property: See Before connect property

Scope

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




Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant