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.
sforbesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inprasCommented:
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
0
inprasCommented:
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
0
sforbesAuthor Commented:
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?

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

inprasCommented:
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?
0
inprasCommented:
Hi sforbes
U R getting the error return code AFX_SQL_ERROR_DATA_TRUNCATED
You requested more data than you have provided storage for so provide more data space in the edit buffer by putting nMaxLength parameter
Hope this helps
Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sforbesAuthor Commented:
Thanks very much.  We didn't think of changing the generated code, but sometimes you have to apparently!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.