473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Cannot Read Varchar(max)

Hi all,
considering the new varchar(max) type I have changed some text columns in
some tables.
The problem is the "SQL Native Client 2005.90.1399.00" odbc driver does not
return any value for this varchar(max) column.
If I use the old odbc driver SQL Server 2000.85.117.00 it works fine.

Any idea why this is not working with the 2005 driver?

Thanks

_______________
Fabio F, Fullin
cel: 15-5479-1821
Jun 27 '08 #1
10 18472
One thing to consider with the SQL Native Client ODBC driver is that
VARCHAR(MAX) has does not have fixed size and the ODBC driver represents
this by returning a max column size of 0. This can confuse your application
if it doesn't check for 0 as a special case. See the bottom section of this
article:
http://msdn.microsoft.com/en-us/library/ms130896.aspx

But in general I have not seen this happen with any of my .NET applications
as it is handled properly in ADO.NET.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #2
Thanks, I found this kind of answers before. But it's not about the max
because
the driver does not return any information at all.
"Plamen Ratchev" <Pl****@SQLStudio.comwrote in message
news:a6******************************@speakeasy.ne t...
One thing to consider with the SQL Native Client ODBC driver is that
VARCHAR(MAX) has does not have fixed size and the ODBC driver represents
this by returning a max column size of 0. This can confuse your
application if it doesn't check for 0 as a special case. See the bottom
section of this article:
http://msdn.microsoft.com/en-us/library/ms130896.aspx

But in general I have not seen this happen with any of my .NET
applications as it is handled properly in ADO.NET.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #3
What is your application, .NET or something else? What happens if you change
the column to VARCHAR(8000) or TEXT, do you see any values? What is the
query that you run?

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #4
yes, if the column is text or varchar(n) it works.
My application is C++ in VisualStudio 2005

"Plamen Ratchev" <Pl****@SQLStudio.comwrote in message
news:87******************************@speakeasy.ne t...
What is your application, .NET or something else? What happens if you
change the column to VARCHAR(8000) or TEXT, do you see any values? What is
the query that you run?

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #5
The code is like this:
oRecordset = getRecordset("select myText from myTable");

while (!oRecordset->IsEOF())
{
oRecordset->GetFieldValue(1,oData);
if (oData.m_dwType == DBVT_ASTRING)
{
sAux = *oData.m_pstringA;
}
oRecordset->MoveNext();
}
If myText is Text or varchar(n) it works fine. But if myText is varchar(max)
*oData.m_pstringA points to an empty string.

My workaround for now is to change the query: "select cast(myText as
varchar(5000)) from myTable"

Thanks,
Diego

"Plamen Ratchev" <Pl****@SQLStudio.comwrote in message
news:87******************************@speakeasy.ne t...
What is your application, .NET or something else? What happens if you
change the column to VARCHAR(8000) or TEXT, do you see any values? What is
the query that you run?

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #6
netzorro (ne******@bluebottle.com) writes:
considering the new varchar(max) type I have changed some text columns
in some tables. The problem is the "SQL Native Client 2005.90.1399.00"
odbc driver does not return any value for this varchar(max) column. If I
use the old odbc driver SQL Server 2000.85.117.00 it works fine.
Maybe you could post the piece of code that is not working? Not that
I can promise to help, since I have not done much ODBC programming.
But at least it gives some idea what the problem might be.

By the way, 1399 is the RTM version of SQL 2005. Maybe this is a bug
that is fixed in SP1 or SP2. So try installing SP2 and see if it helps.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #7
netzorro (ne******@bluebottle.com) writes:
The code is like this:
oRecordset = getRecordset("select myText from myTable");

while (!oRecordset->IsEOF())
{
oRecordset->GetFieldValue(1,oData);
if (oData.m_dwType == DBVT_ASTRING)
{
sAux = *oData.m_pstringA;
}
oRecordset->MoveNext();
}
If myText is Text or varchar(n) it works fine. But if myText is
varchar(max) *oData.m_pstringA points to an empty string.
Wait, didn't you say that you were using ODBC? This looks like ADO
to me.

What does your connection string look like? If you have
PROVIDER=SQLNCLI, try adding DataTypeCompatibility=80 to the
connection string. ADO does not understand the new data types
added to SQL 2005 very well.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #8
I've tried with SP2 too.
SQL Native Client 2005.90.3042.00 and didn't work.
The code is similar but it's ODBC. I define the connection using the odbc
control panel and all.
The same code works for varchar(n) and for text but it doesn't for
varchar(max)
I've seen this error in the web (I'm not the first one with this problem)
but I could never find solution.
Thanks
Diego

"Erland Sommarskog" <es****@sommarskog.sewrote in message
news:Xn**********************@127.0.0.1...
netzorro (ne******@bluebottle.com) writes:
>considering the new varchar(max) type I have changed some text columns
in some tables. The problem is the "SQL Native Client 2005.90.1399.00"
odbc driver does not return any value for this varchar(max) column. If I
use the old odbc driver SQL Server 2000.85.117.00 it works fine.

Maybe you could post the piece of code that is not working? Not that
I can promise to help, since I have not done much ODBC programming.
But at least it gives some idea what the problem might be.

By the way, 1399 is the RTM version of SQL 2005. Maybe this is a bug
that is fixed in SP1 or SP2. So try installing SP2 and see if it helps.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

Jun 27 '08 #9
netzorro (ne******@bluebottle.com) writes:
I've tried with SP2 too.
SQL Native Client 2005.90.3042.00 and didn't work.
The code is similar but it's ODBC.
oRecordset->MoveNext looks awfully much like ADO to me.
I define the connection using the odbc control panel and all.
But how does the connection string look like? If you are using ADO,
use the SQLNCLI provider, and add DataTypeCompatibility=80 to the
connection string.

Since you talk about ODBC, I assume that you use MSDASQL, that is
OLE DB over ODBC. I find it difficult to see any particular reason to
do this.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #10
It has been a very long time since I have used C++...

I am really not sure how those MFC classes recognize the new data types in
SQL Server 2005. Probably worth trying what Erland suggested to set
DataTypeCompatibility=80 in the connection string. I know that does the
trick for ADO.

Did you step through the code to see if the return type is really
DBVT_ASTRING? Just a guess here, but what if you add checks for DBVT_STRING
or DBVT_BINARY. Some frameworks recognize the new data types as binary
objects, so maybe reading as binary and then converting to string will do
it.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Henri | last post by:
Hi, I´ve searching for an reuseable SQL-Statement for follwoing situation: Having e.g. a table tblAdress with some fields like persons full name (as Name), City, Birthdate, Street and so on. ...
75
by: Greg McIntyre | last post by:
I have a Python snippet: f = open("blah.txt", "r") while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit...
7
by: Ryan | last post by:
I've stumbled across the above error and am a little stuck. I've just installed SQL2000 (sp3) on my PC and restored a database from our Live server. On a simple Update statement on a #temp table,...
6
by: mike | last post by:
so I keep optimizing my fields down to the minimum character length necessary i.e., varchar(15), then I find out a month later its gotta get bigger, then a few months later, bigger again, etc. ...
5
by: Jay | last post by:
My understanding is that char stores a fixed number of characters even if the string stored in the char has fewer characters, whereas varchar stores the string with the number of characters that...
0
by: wmos4995 | last post by:
Hi, I am writing a procedure to alter the value of a sequence to max value of the table column. This is what i have written till now. CREATE PROCEDURE RESET_SEQ ( IN TABNAME VARCHAR(50),...
4
by: parez | last post by:
Hi, When does the socket (server) know when to stop reading. e.g. if i have a buffer = 25K and do networkStream.write twice.. what will the server read? 25k or 50K?
2
by: Bill E. | last post by:
SQL Server 2005 Simple scenario - We want to store answers to survey questions. Some questions require very short responses (one or two words) while others require long essay type responses. ...
1
by: quintonmartin | last post by:
Here's my problem. I have a client application that uses a web service for data access. I can read/update many records in many tables, however, I am not getting what I expect for a varbinary(max)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.