Solved

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

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

744 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

10 Experts available now in Live!

Get 1:1 Help Now