?
Solved

ODBC, SqlServer and VarBinary Columns

Posted on 1999-12-14
6
Medium Priority
?
522 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:sforbes
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:inpras
ID: 2280145
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
 
LVL 4

Expert Comment

by:inpras
ID: 2280158
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
 

Author Comment

by:sforbes
ID: 2280798
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:inpras
ID: 2282466
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
 
LVL 4

Accepted Solution

by:
inpras earned 400 total points
ID: 2282490
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
 

Author Comment

by:sforbes
ID: 2283649
Thanks very much.  We didn't think of changing the generated code, but sometimes you have to apparently!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question