Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 weird char/varchar bug

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-31 : 09:14:14
Joe Enzminger writes "We are connecting to a SQL Server 2000 instance using OLEDB. When processing results from the following statement:

select 'spResult' as Result

we get some odd output:

When you run this in query analyzer, you get what you'd expect

Result
spResult

Using OLEDB, binding the Row using the information provided by the Rowset object, I get

Result
spResul

Note, the last character is truncated.

If I change the code to

declare @Result varchar(256)
set @Result = 'spResult'

select @Result as Result

I get:

Result
spResult

Using both methods. Has anyone seen this behavior before? I am trying to figure out if the bug is in my OLEDB code or if it is in the driver at some level. I can provide the code I am using to bind the data in our OLEDB code if necessary.

Thanks,

Joe Enzminger"

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-05-31 : 10:43:37
quote:
Using OLEDB, binding the Row using the information provided by the Rowset object, I get

Result
spResul


If you use something like select 'spresultaandbandcandlonger' as 'Result' does it still truncate it down to 7 chars or does it just cut the last one? I've seen something simular for this, but it was 200 chars +

Go to Top of Page

joeenzminger
Starting Member

2 Posts

Posted - 2002-05-31 : 12:28:28
It just cuts off the last character, irregardless of the length. However, I have not tried very long strings (> 200 characters).

Joe

quote:

Joe Enzminger writes "We are connecting to a SQL Server 2000 instance using OLEDB. When processing results from the following statement:

select 'spResult' as Result

we get some odd output:

When you run this in query analyzer, you get what you'd expect

Result
spResult

Using OLEDB, binding the Row using the information provided by the Rowset object, I get

Result
spResul

Note, the last character is truncated.

If I change the code to

declare @Result varchar(256)
set @Result = 'spResult'

select @Result as Result

I get:

Result
spResult

Using both methods. Has anyone seen this behavior before? I am trying to figure out if the bug is in my OLEDB code or if it is in the driver at some level. I can provide the code I am using to bind the data in our OLEDB code if necessary.

Thanks,

Joe Enzminger"



Go to Top of Page

VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2002-05-31 : 12:54:50
Are you using OLE DB API from a C++ application? Did you test your code with a proper char/varchar column, to see if it's retrieving the complete value?

--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page

joeenzminger
Starting Member

2 Posts

Posted - 2002-06-03 : 13:21:21
Thank you for the reply -

Yes, we are using the C++ OLE DB API. I have tested several different cases, with different results:

Using datatype varchar(256), the data comes back correctly
Using datatype char(256), the data comes back, but with spaces padding out empty data.

Passing the string directly, as in:

select 'spResult'

Causes the last character to be truncated.

Thanks,

Joe


Go to Top of Page

VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2002-06-05 : 05:38:21
The behavior you observed with varchar(256) and char(256) is expected.

I am not sure why "select 'spResult' as Result" is losing one character. Could be a problem with your code, because I haven't seen this behavior when using OLE DB provider via ADO :-)

It's worth a search on Microsoft KB though.

--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page
   

- Advertisement -