Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CLongBinary Limited to 255 Bytes

CLongBinary Limited to 255 Bytes

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasesql-serversysadminperformance
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Drakesal
    wrote on last edited by
    #1

    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

    L S 3 Replies Last reply
    0
    • D Drakesal

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Where is the code that raises the error and what are the values of the parameters being referenced?

      D 1 Reply Last reply
      0
      • L Lost User

        Where is the code that raises the error and what are the values of the parameters being referenced?

        D Offline
        D Offline
        Drakesal
        wrote on last edited by
        #3

        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?

        L 1 Reply Last reply
        0
        • D Drakesal

          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?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          D 1 Reply Last reply
          0
          • L Lost User

            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.

            D Offline
            D Offline
            Drakesal
            wrote on last edited by
            #5

            Ok already posted the code the problem occur in the moment i call Update, and when the file is greater than 255kb

            D 1 Reply Last reply
            0
            • D Drakesal

              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

              S Offline
              S Offline
              Stefan_Lang
              wrote on last edited by
              #6

              Have you verified that GlobalAlloc actually worked? Does file.Read() actually read the full file? Check the return value of the Read function to see how many bytes have been read. 255K doesn't seem that large. However, the Global** functions and the CFile 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 use GMEM_MOVEABLE? And since you immediately free the memory after use, why do you even use the GLOBAL** functions at all, why don't you simply use new and delete 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)

              L 1 Reply Last reply
              0
              • S Stefan_Lang

                Have you verified that GlobalAlloc actually worked? Does file.Read() actually read the full file? Check the return value of the Read function to see how many bytes have been read. 255K doesn't seem that large. However, the Global** functions and the CFile 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 use GMEM_MOVEABLE? And since you immediately free the memory after use, why do you even use the GLOBAL** functions at all, why don't you simply use new and delete 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)

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Stefan_Lang wrote:

                why

                Stefan_Lang wrote:

                why do you

                Stefan_Lang wrote:

                why don't you

                Copy & Paste ?

                1 Reply Last reply
                0
                • D Drakesal

                  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

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  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

                  D 1 Reply Last reply
                  0
                  • L Lost User

                    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

                    D Offline
                    D Offline
                    Drakesal
                    wrote on last edited by
                    #9

                    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:

                    1 Reply Last reply
                    0
                    • D Drakesal

                      Ok already posted the code the problem occur in the moment i call Update, and when the file is greater than 255kb

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups