asynchronous connection w/ odbc to ms sql database -- C Coding

This is a discussion on asynchronous connection w/ odbc to ms sql database -- C Coding within the Windows Programming forums, part of the Platform Specific Boards category; My current program, connects to the database synchronously. It uploads the data and can pull down the records it needs. ...

  1. #1
    Registered User
    Join Date
    Dec 2013
    Posts
    2

    asynchronous connection w/ odbc to ms sql database -- C Coding

    My current program, connects to the database synchronously. It uploads the data and can pull down the records it needs.

    I have been given the task of making the connection asynchrounous.

    I have the latest ODBC 3.8 and Windows 7 which does support the asynchronous connections (pooling method).

    Can anyone point me in the right direction or maybe a piece of sample code?

  2. #2
    Registered User
    Join Date
    Dec 2013
    Posts
    2
    This example shows how to use SQLSetConnectAttr to enable asynchronous execution for connection-related functions.
    Code:
    
    
    
    BOOL AsyncConnect (SQLHANDLE hdbc) 
    {
    
        SQLRETURN r;
        SQLHANDLE hdbc;
    
        // Enable asynchronous execution of connection functions.
    // This must be executed synchronously, that is r != SQL_STILL_EXECUTING
    
       r = SQLSetConnectAttr(hdbc, SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE,
             reinterpret_cast<SQLPOINTER>(SQL_ASYNC_DBC_ENABLE_ON), 0);
    
        if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) 
        {
           return FALSE;
        }
    
    
        TCHAR szConnStrIn[256] = _T("DSN=AsyncDemo");
        r = SQLDriverConnect(hdbc, NULL, (SQLTCHAR *) szConnStrIn, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
    
        if (r == SQL_ERROR) 
        {
           // Use SQLGetDiagRec to process the error.
    // If SQLState is HY114, the driver does not support asynchronous execution.
    return FALSE;
        }
    
    
        while (r == SQL_STILL_EXECUTING) 
        {
           // Do something else.
    // Check for completion, with the same set of arguments.
    
          r = SQLDriverConnect(hdbc, NULL, (SQLTCHAR *) szConnStrIn, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
        }
    
        if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) 
        {
           return FALSE;
        }
        return TRUE;
    }
    

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ODBC DSN-less connection
    By esaptonor in forum Windows Programming
    Replies: 8
    Last Post: 06-15-2007, 12:09 AM
  2. ODBC Connection
    By StephanC in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 02:08 AM
  3. ODBC connection not using MFC
    By knutso in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2003, 07:39 AM
  4. ODBC Connection
    By Marky_Mark in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2001, 03:40 PM
  5. ODBC connection
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 09-07-2001, 09:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21