Creating a trusted connection

Using your application, you can create a trusted connection to your database.

Before you begin

Before you can create a trusted connection, ensure that you have met the following prerequisites:

  • The trusted-context object is enabled.
  • Your user ID has CONNECT privileges to the database.
  • Your user ID matches the primary user ID in the trusted-context object.
  • Your connection request is coming from a trusted location that is defined in the trusted-context object.

Procedure

To request a trusted connection, use the appropriate command from within your application.
  • HCL OneDB™ ESQL/C

    Use the TRUSTED keyword within the existing CONNECT statement.

    EXEC SQL CONNECT TO 'database_name' TRUSTED;
  • HCL OneDB JDBC Driver

    Include the TRUSTED_CONTEXT=TRUE; property in the database URL.

    jdbc:informix-sqli://hostname:portnumber/database_name:
          INFORMIXSERVER = server_name; TRUSTED_CONTEXT=TRUE;
  • HCL OneDB ODBC Driver

    Local transactions are supported on the IBM Informix ODBC Driver, but distributed (XA) transactions are not.

    For local transactions, call the SQLSetConnectAttr function to set the SQL_ATTR_USE_TRUSTED_CONTEXT attribute before you open a connection.

    SQLSetConnectAttr( hdbc, SQL_ATTR_USE_TRUSTED_CONTEXT,
          SQL_TRUE, SQL_IS_INTEGER );

    You can also request a connection by including the TCTX = 1 attribute in the connection string.

    SQLDriverConnect( hdbc, NULL, "DSN = MyDSN; TCTX = 1",
          SQL_NTS,ConnStrOutp, 250, &pcbConnStrOut, SQL_DRIVER_NOPROMPT );