Connecting to a data source

After environment and connection handles have been allocated, the application can connect to the data source using one of these subfunctions:

  • SQLConnect

    This passes a connection handle, a data source name, a login ID or account name, and an authentication string, or password. The lengths of the strings are also passed. Depending on the data source, the login ID and the password may be optional. SQL_NTS is used to indicate that the corresponding parameter is a null-terminated character string.

    odbc SQLConnect $hdbc MSSQLServer SQL_NTS golan \
         SQL_NTS golan SQL_NTS
  • SQLDriverConnect

    This connects to data sources which require more information than the arguments supported by SQLConnect. Dialog boxes are not supported for this function. The connection string argument is used to pass all necessary data source-specific connection information.

    odbc SQLDriverConnect $hdbc NULL \
        "DSN=MSSQLServer;UID=golan;PWD=golan" SQL_NTS \
        OutConnectionString 128 StringLengthPtr \
        SQL_DRIVER_NOPROMPT
  • SQLBrowseConnect

    This determines, in iterative fashion, the necessary information that is required for connection establishment. It must be called a minimum of two times to establish a connection. After a successful connection is established, the connection string it returns can be used with SQLDriverConnect for subsequent connection to the same data source.

    odbc SQLBrowseConnect $hdbc \
        "DSN=MSSQLServer;UID=golan;PWD=golan; \
        ADDRESS=odbctest" SQL_NTS OutConnectionString \ 
        512 StringLength2Ptr