Solved

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

Posted on 2008-06-11
4
333 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 250 total points
ID: 21764527
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 250 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

635 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