I am executing the following simple query in SQL Server Management Studio:
SELECT name, definition FROM sys.default_constraints
This works fine and I can see that there are some rows in my data. I try to execute the same query in my test application (implemented in C++), using ODBC in the following way, using SQLGetData:
SQLGetData( *pStatementHandle, i, SQL_C_WCHAR, pvData ,nLen, &nActualLen ) );
The result is successful, but my buffer,pvData, is empty. I have tried some other applications that use ODBC as well to see if I am missing something but they also fail to retrieve any data. Am I missing something Or is this only possible using SQL Native Client
Any pointers, clues
Thanks in advance,
Mohan

SQLGetData returns an empty buffer on Query (ODBC)
Mandypenny
From this code snippet it's hard to tell exactly what's wrong.
First thing to check would be the return code from 'SQLFetch()', called just before SQLGetData(). If this returns "SQL_NO_DATA_FOUND", then you're probably in the wrong database. Try executing 'use <database>' prior to your call.
If 'SQLFetch()' returns SQL_SUCCESS, then you have something wrong with your SQLGetData() call.
1) You're binding as 'SQL_C_WCHAR'. Is 'pvData' an array of char's or wchar's
2) What's your value for nLen Is it non-zero
3) Is your column number correct (i == 1 for 'name' column, etc. )
4) What's returned by nActualLength Is it 'SQL_NULL_DATA', or is it a positive number. If it's positive, then go back and check point 1) above.
Hope this helps. If not, please attach a more lengthy code sample. I may be missing something.
~Warren