Solved

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

Posted on 2008-06-11
4
302 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
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Message not shown 5 29
Way to decrease size of apk file 9 40
SQL Server Question 5 25
SQL Server stored proc 2 10
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

930 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now