CLongBinary Limited to 255 Bytes
-
Hi all I am writing a program to submit some files in a SQL server 2012 the problem is: when the file size is around 255 KBytes it's all ok, but when the file is greater there is an error on "RecordSet.Update() phase. The error is : "The Pointer Value type Text, NText or image conflicts with the specified column name. ..." The Column is declared in table as varbinary(max) the code is:
CFile file(szPathFileToOpen, CFile::modeRead); ULONGLONG filelen = file.GetLength(); rsAttachments.AddNew(); rsAttachments.m\_AttachmentsID=szUniqueID; rsAttachments.m\_FileName=m\_ListAttached.GetItemText(0,0); GlobalFree( rsAttachments.m\_FileData.m\_hData ); if((rsAttachments.m\_FileData.m\_hData=GlobalAlloc(GMEM\_MOVEABLE,filelen))==NULL) { AfxMessageBox(\_T("memory error")); } LPVOID pVoid = NULL; if((pVoid=GlobalLock(rsAttachments.m\_FileData.m\_hData))== NULL) { AfxMessageBox( \_T( "memory error" )); } file.Read(pVoid, filelen); rsAttachments.SetFieldDirty( &rsAttachments.m\_FileData, TRUE ); rsAttachments.SetFieldNull( &rsAttachments.m\_FileData, FALSE ); rsAttachments.m\_FileData.m\_dwDataLength=GlobalSize(rsAttachments.m\_FileData.m\_hData ); rsAttachments.Update(); GlobalFree( rsAttachments.m\_FileData.m\_hData );
Thanks in advance to the angel will help me. Giovanni
-
Hi all I am writing a program to submit some files in a SQL server 2012 the problem is: when the file size is around 255 KBytes it's all ok, but when the file is greater there is an error on "RecordSet.Update() phase. The error is : "The Pointer Value type Text, NText or image conflicts with the specified column name. ..." The Column is declared in table as varbinary(max) the code is:
CFile file(szPathFileToOpen, CFile::modeRead); ULONGLONG filelen = file.GetLength(); rsAttachments.AddNew(); rsAttachments.m\_AttachmentsID=szUniqueID; rsAttachments.m\_FileName=m\_ListAttached.GetItemText(0,0); GlobalFree( rsAttachments.m\_FileData.m\_hData ); if((rsAttachments.m\_FileData.m\_hData=GlobalAlloc(GMEM\_MOVEABLE,filelen))==NULL) { AfxMessageBox(\_T("memory error")); } LPVOID pVoid = NULL; if((pVoid=GlobalLock(rsAttachments.m\_FileData.m\_hData))== NULL) { AfxMessageBox( \_T( "memory error" )); } file.Read(pVoid, filelen); rsAttachments.SetFieldDirty( &rsAttachments.m\_FileData, TRUE ); rsAttachments.SetFieldNull( &rsAttachments.m\_FileData, FALSE ); rsAttachments.m\_FileData.m\_dwDataLength=GlobalSize(rsAttachments.m\_FileData.m\_hData ); rsAttachments.Update(); GlobalFree( rsAttachments.m\_FileData.m\_hData );
Thanks in advance to the angel will help me. Giovanni
-
Where is the code that raises the error and what are the values of the parameters being referenced?
i am a novice with a DB programming i have put now a CDBException that return me this: m_strStateNativeOrigin = "State:37000,Native:7125,Origin:[Microsoft][ODBC SQL Server Driver][SQL Server] State:S1000,Native:0,Origin:[Microsoft][ODBC SQL Server Driver] It's good this?
-
i am a novice with a DB programming i have put now a CDBException that return me this: m_strStateNativeOrigin = "State:37000,Native:7125,Origin:[Microsoft][ODBC SQL Server Driver][SQL Server] State:S1000,Native:0,Origin:[Microsoft][ODBC SQL Server Driver] It's good this?
-
Sorry, that means nothing. You need to show the exact code that causes the error, and include the values of all the parameters being used.
-
Hi all I am writing a program to submit some files in a SQL server 2012 the problem is: when the file size is around 255 KBytes it's all ok, but when the file is greater there is an error on "RecordSet.Update() phase. The error is : "The Pointer Value type Text, NText or image conflicts with the specified column name. ..." The Column is declared in table as varbinary(max) the code is:
CFile file(szPathFileToOpen, CFile::modeRead); ULONGLONG filelen = file.GetLength(); rsAttachments.AddNew(); rsAttachments.m\_AttachmentsID=szUniqueID; rsAttachments.m\_FileName=m\_ListAttached.GetItemText(0,0); GlobalFree( rsAttachments.m\_FileData.m\_hData ); if((rsAttachments.m\_FileData.m\_hData=GlobalAlloc(GMEM\_MOVEABLE,filelen))==NULL) { AfxMessageBox(\_T("memory error")); } LPVOID pVoid = NULL; if((pVoid=GlobalLock(rsAttachments.m\_FileData.m\_hData))== NULL) { AfxMessageBox( \_T( "memory error" )); } file.Read(pVoid, filelen); rsAttachments.SetFieldDirty( &rsAttachments.m\_FileData, TRUE ); rsAttachments.SetFieldNull( &rsAttachments.m\_FileData, FALSE ); rsAttachments.m\_FileData.m\_dwDataLength=GlobalSize(rsAttachments.m\_FileData.m\_hData ); rsAttachments.Update(); GlobalFree( rsAttachments.m\_FileData.m\_hData );
Thanks in advance to the angel will help me. Giovanni
Have you verified that
GlobalAlloc
actually worked? Doesfile.Read()
actually read the full file? Check the return value of theRead
function to see how many bytes have been read. 255K doesn't seem that large. However, theGlobal**
functions and theCFile
class are ancient, and I wouldn't be surprised if they had some built-in restrictions... On a sidenote, since you immediately lock the memory after allocation, why do you useGMEM_MOVEABLE
? And since you immediately free the memory after use, why do you even use theGLOBAL**
functions at all, why don't you simply usenew
anddelete
instead? That would be faster, requires less code, and takes less effort to read and understand the code!GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
Have you verified that
GlobalAlloc
actually worked? Doesfile.Read()
actually read the full file? Check the return value of theRead
function to see how many bytes have been read. 255K doesn't seem that large. However, theGlobal**
functions and theCFile
class are ancient, and I wouldn't be surprised if they had some built-in restrictions... On a sidenote, since you immediately lock the memory after allocation, why do you useGMEM_MOVEABLE
? And since you immediately free the memory after use, why do you even use theGLOBAL**
functions at all, why don't you simply usenew
anddelete
instead? That would be faster, requires less code, and takes less effort to read and understand the code!GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
Hi all I am writing a program to submit some files in a SQL server 2012 the problem is: when the file size is around 255 KBytes it's all ok, but when the file is greater there is an error on "RecordSet.Update() phase. The error is : "The Pointer Value type Text, NText or image conflicts with the specified column name. ..." The Column is declared in table as varbinary(max) the code is:
CFile file(szPathFileToOpen, CFile::modeRead); ULONGLONG filelen = file.GetLength(); rsAttachments.AddNew(); rsAttachments.m\_AttachmentsID=szUniqueID; rsAttachments.m\_FileName=m\_ListAttached.GetItemText(0,0); GlobalFree( rsAttachments.m\_FileData.m\_hData ); if((rsAttachments.m\_FileData.m\_hData=GlobalAlloc(GMEM\_MOVEABLE,filelen))==NULL) { AfxMessageBox(\_T("memory error")); } LPVOID pVoid = NULL; if((pVoid=GlobalLock(rsAttachments.m\_FileData.m\_hData))== NULL) { AfxMessageBox( \_T( "memory error" )); } file.Read(pVoid, filelen); rsAttachments.SetFieldDirty( &rsAttachments.m\_FileData, TRUE ); rsAttachments.SetFieldNull( &rsAttachments.m\_FileData, FALSE ); rsAttachments.m\_FileData.m\_dwDataLength=GlobalSize(rsAttachments.m\_FileData.m\_hData ); rsAttachments.Update(); GlobalFree( rsAttachments.m\_FileData.m\_hData );
Thanks in advance to the angel will help me. Giovanni
Hi,
Drakelor wrote:
when the file size is around 255 KBytes it's all ok, but when the file is greater there is an error on "RecordSet.Update() phase. The error is : "The Pointer Value type Text, NText or image conflicts with the specified column name. ..."
You are probably storing the file into a BLOB column. All SQL columns usually have a maximum size. The error message is probably correct... if you attempt to stuff 256 KBytes into a 255 KByte data field you will obviously get an error. I suspect that you need to regenerate your database tables. This time choose a larger column size. Best Wishes, -David Delaune
-
Hi,
Drakelor wrote:
when the file size is around 255 KBytes it's all ok, but when the file is greater there is an error on "RecordSet.Update() phase. The error is : "The Pointer Value type Text, NText or image conflicts with the specified column name. ..."
You are probably storing the file into a BLOB column. All SQL columns usually have a maximum size. The error message is probably correct... if you attempt to stuff 256 KBytes into a 255 KByte data field you will obviously get an error. I suspect that you need to regenerate your database tables. This time choose a larger column size. Best Wishes, -David Delaune
I finally resolved the issue. I explain to you. 1) Download last SQL server driver. 2) Rebind/Recreate the CRecordset, so it bind with varbinary(max) -> CBYTEARRAY 3) In Recordset Class in the line : RFX_Binary(pFX, _T("[FileData]"), m_FileData,15360000); increase the last parameter to desidered max dimension (15MB in my case). 4) Write this simple code:
CFile cfFileToSave(szPathFileToOpen,CFile::modeRead); rsAttachments.m\_FileData.SetSize((INT\_PTR)cfFileToSave.GetLength()); cfFileToSave.Read(rsAttachments.m\_FileData.GetData(),(UINT)cfFileToSave.GetLength()); cfFileToSave.Close(); rsAttachments.SetFieldDirty(&rsAttachments.m\_FileData,TRUE); rsAttachments.SetFieldNull(&rsAttachments.m\_FileData,FALSE); rsAttachments.Update();
All done thanks all :thumbsup:
-
Ok already posted the code the problem occur in the moment i call Update, and when the file is greater than 255kb
So have you stepped into
Update()
, using the debugger, to see where the exception is being thrown from?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles