Creating a trusted connection
Using your application, you can create a trusted connection to your database.
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.
- IBM Informix ESQL/C
Use the TRUSTED keyword within the existing CONNECT statement.
EXEC SQL CONNECT TO 'database_name' TRUSTED;
- IBM Informix 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;
- IBM Informix 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 );
Note: - IBM Data Server Driver for JDBC and SQLJ
- For local transactions, use the getDB2TrustedPooledConnection
method.
getDB2TrustedPooledConnection( String user_ID, String user_password, java.util.Properties properties );
- For distributed transactions, use one of the following getDB2TrustedXAConnection
methods.
getDB2TrustedXAConnection( String user_ID, String user_password, java.util.Properties properties );
getDB2TrustedXAConnection( java.util.Properties properties );
- For local transactions, use the getDB2TrustedPooledConnection
method.
- IBM Data Server Provider for .NET
Use the TrustedContextSystemUserID and TrustedContextSystemPassword properties in the connection string.
String connectString = " Server = IP_address/Local_host:port_number; Database = database_name; TrustedContextSystemUserID = user_ID; TrustedContextSystemPassword = user_password; ";