[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

What is the best way to get a varchar(max) from ADO

Posted on 2008-10-16
7
Medium Priority
?
645 Views
Last Modified: 2012-05-05
I have a SQL Express column of type varchar(max).  What is the best way to extract the column value using ADO in VBA?  Do I  need to declare and use the Windows API Function: WideCharToMultiByte to use the value as text?

A value of correct length is returned but not as a recognizable or usable string.
Set oADOConn = CreateObject("ADODB.Connection") 
oADOConn.ConnectionString = oConnString
oADOConn.Open
 
Set oADOCommand = CreateObject("ADODB.Command")
oADOCommand.ActiveConnection = oADOConn
oADOCommand.CommandType = adCmdStoredProc
oADOCommand.NamedParameters = False
oADOCommand.CommandText = "GetSCFText"    
Set oADORecSet = oADOCommand.Execute
   
vSCFText = oADORecSet.fields("SCFText").value
        
    oADOConn.Close                                                        ' Close the ADO Connection
    
    Set oADOConn = Nothing                                                ' Release the ADO Connection
    Set oADOCommand = Nothing                                             ' Release the ADO Command

Open in new window

0
Comment
Question by:MDKIMZEY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:JonMny
ID: 22732091
String variable type will work fine
dim  vSCFText as string
 
0
 

Author Comment

by:MDKIMZEY
ID: 22733459
Actually the string comes through as binary.
0
 
LVL 9

Expert Comment

by:JonMny
ID: 22733479
I tested it on my system and works fine, what is stored in your field? How large is it?
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:MDKIMZEY
ID: 22733651
JonMny, Thanks much for looking at this and trying it on your system - the column SCFText is declared as SCFTEXT varchar(max)  in SQL Express 2005.

What version of SQL and MDAC are you using?
0
 
LVL 9

Accepted Solution

by:
JonMny earned 375 total points
ID: 22733761
I have sql server 2008 not sure what version of mdac, I used excel 2007 to test it.
Sub sdefla()
Set oADOConn = CreateObject("ADODB.Connection")
oADOConn.ConnectionString = "server=.\dev;Integrated Security=SSPI;database=test;provider=sqloledb"
 
 
 
oADOConn.Open
 
Set oADOCommand = CreateObject("ADODB.Command")
oADOCommand.ActiveConnection = oADOConn
oADOCommand.CommandType = 4
oADOCommand.NamedParameters = False
oADOCommand.CommandText = "gettest"
Set oADORecSet = oADOCommand.Execute
   
vSCFText = oADORecSet.fields("test").Value
        
    oADOConn.Close                                                        ' Close the ADO Connection
    
    Set oADOConn = Nothing                                                ' Release the ADO Connection
    Set oADOCommand = Nothing                                             ' Release
End Sub

Open in new window

0
 

Author Closing Comment

by:MDKIMZEY
ID: 31506745
I appreciate your looking at this - I changed the column definition from varchar(max) to text - this did the trick...
0
 

Author Comment

by:MDKIMZEY
ID: 22734059
This may be an issue with SQL Express 2005 and ADO 2.8 - the solution I used was to change the varchar(max) column to a text column and add a SET TEXTSIZE statement to the stored procedure.  

I did try using a call to:

Private Declare Function WideCharToMultiByte Lib "kernel32" _
    (ByVal codepage As Long, ByVal dwFlags As Long, _
    lpWideCharStr As Any, ByVal cchWideChar As Long, _
    lpMultiByteStr As Any, ByVal cchMultiByte As Long, _
    ByVal lpDefaultChar As String, _
    ByVal lpUsedDefaultChar As Long) As Long

on the binary data in the Value property of the ADO Field.  This had no affect.


0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
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.
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.

649 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