Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
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.

856 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