ODBC connection functions

ODBC supplies a set of connection functions. Which one you use depends on how you expect your application to be deployed and used:

  • SQLConnect   The simplest connection function.

    SQLConnect takes a data source name and optional user ID and password. You may want to use SQLConnect if you hard-code a data source name into your application.

    For more information, see SQLConnect in the Microsoft ODBC API Reference at [external link] http://msdn.microsoft.com/en-us/library/ms711810.aspx.

  • SQLDriverConnect   Connects to a data source using a connection string.

    SQLDriverConnect allows the application to use SQL Anywhere-specific connection information that is external to the data source. Also, you can use SQLDriverConnect to request that the SQL Anywhere driver prompt for connection information.

    SQLDriverConnect can also be used to connect without specifying a data source. The SQL Anywhere ODBC driver name is specified instead. The following example connects to a server and database that is already running.

    SQLSMALLINT cso;
    SQLCHAR     scso[2048];
    
    SQLDriverConnect( hdbc, NULL,
       "Driver=SQL Anywhere 12;UID=DBA;PWD=sql", SQL_NTS,
       scso, sizeof(scso)-1,
       &cso, SQL_DRIVER_NOPROMPT );

    For more information, see SQLDriverConnect in the Microsoft ODBC API Reference at [external link] http://msdn.microsoft.com/en-us/library/ms715433.aspx.

  • SQLBrowseConnect   Connects to a data source using a connection string, like SQLDriverConnect.

    SQLBrowseConnect allows your application to build its own windows to prompt for connection information and to browse for data sources used by a particular driver (in this case the SQL Anywhere driver).

    For more information, see SQLBrowseConnect in the Microsoft ODBC API Reference at [external link] http://msdn.microsoft.com/en-us/library/ms714565.aspx.

 See also

Establishing a connection