Link to home
Start Free TrialLog in
Avatar of sforbes
sforbes

asked on

ODBC, SqlServer and VarBinary Columns

How does one use the binary fields in MSSQL from Visual C++?
When using the class wizard to create the class for the DB Table,
the binary field maps to a CByteArray.  I can write to this table,
but if I read, I get a data truncation error.  The rather ambiguous
help files on MFC suggest using CLongBinary instead, but the
CLongBinary documentation says to use CByteArray.
Avatar of inpras
inpras

Hi
Its better use CByteArray because U get more functionalities
If Ur Requirement gets satisfy with CLongBinary go ahead with it there is absolutely no probs with it

only concern is UR getting a warning (hoping no error)of truncation  that any way will come even if U use CLongBinary because the DDX_Binary imlementation problems
Regards
Continuing with what i said earlier
the following function
it should be DFX not DDX
The DFX_Binary function transfers arrays of bytes between the field data members of a CDaoRecordset object and the columns of a record on the data source. Data is mapped between type DAO_BYTES in DAO and type CByteArray in the recordset.


void AFXAPI DFX_Binary( CDaoFieldExchange* pFX, LPCTSTR szName, CByteArray& value, int nPreAllocSize = AFX_DAO_BINARY_DEFAULT_SIZE, DWORD dwBindOptions = 0 );

u can go to afxdao.h file and change the size of AFX_DAO_BINARY_DEFAULT_SIZE
then U will get better results.
Hope this helps
Regards
Avatar of sforbes

ASKER

We are using ODBC not DAO.  The problem we are experiencing is that we do the following:

// Sometable is empty

Sometable tt;

tt.Open(ourDB_p);

tt.AddNew(...)

tt.Update()

tt.Close()

Everthing is fine to here.  When at another time we do:

Sometable tt;

tt.Open(ourDB_p);

The open throws an exception, the text of which tells us that the Data has been truncated.

Our thesis is that the Rfx_Binary function is not handling the CByteArray properly.

Why not?

Oops

sorry any how the RFX_Binary is implemented in ODBC also check R U passing the fourth parameter nMaxLength and not using the default one which is 255?
ASKER CERTIFIED SOLUTION
Avatar of inpras
inpras

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sforbes

ASKER

Thanks very much.  We didn't think of changing the generated code, but sometimes you have to apparently!