CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Apr 2006
    Posts
    1

    C ODBC demo not working

    Following is simple connection demo.I using VC++ 8.0 ( windows server 2003 )to compile and getting lots of compilation errors.
    could anybody please help me with this.
    sample of the errors are :
    :\program files\microsoft visual studio 8\vc\platformsdk\include\sqltypes.h(149) : error C2054: expected '(' to follow 'SQLHWND'
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\sqltypes.h(153) : error C2085: 'DATE_STRUCT' : not in formal parameter list
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\sqltypes.h(156) : error C2085: 'DATE_STRUCT' : not in formal parameter list
    c:\program files\microsoft visual studio 8\vc\platformsdk\include\sqltypes.h(156) : error C2146: syntax error : missing ',' before identifier 'SQL_DATE_STRUCT'
    this is the seemingly harmless code :
    Code:
    #include <windows.h>
    #include <sqlext.h>
    #include <sql.h>
    #include <stdio.h>
    
    
    main() 
    {
    	SQLHENV     henv;
    	SQLHDBC     hdbc;
    	SQLHSTMT    hstmt;
    	SQLRETURN   retcode;
    
    		  /*Allocate environment handle */
    	retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
    	/* Set the ODBC version environment attribute */
    	retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 
        /* Allocate connection handle */
        retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 
        /* Set login timeout to 5 seconds. */
        SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (void*)5, 0);
    	 /* Connect to data source */
    	 retcode = SQLConnect(hdbc, (SQLWCHAR*) "Sales", SQL_NTS,
    					  (SQLWCHAR*) "JohnS", SQL_NTS,
    					  (SQLWCHAR*) "Sesame", SQL_NTS);
    						/* Allocate statement handle */
    	 retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); 
    
    				if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
    				/* Process data */
    					  ;
    					  ;
    					  ;
    
    				   SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
    				}
    	  SQLDisconnect(hdbc);
    	  SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
    	  SQLFreeHandle(SQL_HANDLE_ENV, henv);
    }
    Thankz
    Last edited by Ejaz; April 10th, 2006 at 07:24 AM. Reason: Tags added

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured