Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can i fetch a value from database which field is of type ntext

Posted on 2008-06-11
4
Medium Priority
?
341 Views
Last Modified: 2013-11-20
hi,

       i have an application in which i need to fetch the record from SQL Server Database, i am using CRecordSet::GetFieldValue(index, string) function when i am fetching a data that is ntext type then an error  "out of memory" occurs in others case it is working properly.
0
Comment
Question by:rajnish1579
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 31

Accepted Solution

by:
James Murrell earned 1000 total points
ID: 21764527
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 1000 total points
ID: 21766324
The memory exception would have been thrown by the CString logic, and it does that when it can't allocate enough memory.  I'd say that the actual error occurs when CRecordset calls
   CString::GetBufferSetLength(nLen)
where nLen is the actual size of the data in the field as determined (ultimately) by a call to
    ::SQLDescribeCol()

=-=-=-=-=-=
Alas, I've never seen this fail.  It might fail if your computer was really short of memory and the ntext field was really large.  Have you detected any pattern to the failure?  Does it always fail if the field length is particularly large?

In Query Analyzer, you can use
  SELECT DATALENGTH( MyColumnName) FROM MyTable WHERE...
to find out how large the field is, in characters.

=-=-=-==-=-=
Note that there could be a problem if your program has not been built as a UNICODE project (or if not linked with the correct (UNICODE) MFC DLL).  In that case, calculations would be wrong by a factor of 2.

=-=-=-==-=-=
If you can't solve this, you could try using a different version of the GetFieldValue() funtion... the one that specifies to place the data into a CDbVariant data type.  There is an example of that usage here (near the bottom)

  CRecordset::GetFieldValue  
   http://msdn.microsoft.com/en-us/library/5f8k59f9(VS.80).aspx

After the data is obtained, you can use
   varValue.m_pstringW  
to obtain the UNICODE string text.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

715 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