Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I Need Help w/ XML

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
I am new to XML and am trying to set up a simple vb app to send a SQL command to an asp page and receive a recordset back via XML. In my VB app I am getting an "error 91 - object variable or with block variable not set." on the following line of code:

Set xmldoc = xttp.responseXML

Below is my VB code as well as my ASP code. I hope someone can help me resolve this. Thanks in advance for any help.

--------------------
VB CODE
--------------------
Dim s
Dim r As ADODB.Recordset

Private Sub Command1_Click()
Dim xttp As MSXML2.XMLHTTP
Dim xmldoc As MSXML2.DOMDocument
Set xhttp = New MSXML2.XMLHTTP
'Set xmldoc = New MSXML2.DOMDocument
xhttp.open "post", " False
xhttp.send s
Set xmldoc = xttp.responseXML
xmldoc.save "c:\testxml.xml"
Set r = New ADODB.Recordset
r.open "c:\testxml.xml", "provider=mspersist"
MsgBox r.RecordCount
End Sub

Private Sub Form_Load()
s = &quot;<?xml version=&quot;&quot;1.0&quot;&quot;?>&quot; & vbCrLf
s = s & &quot;<command>&quot;
s = s & &quot;<commandtext>select * from users</commandtext>&quot;
s = s & &quot;<returnsdata>True</returnsdata>&quot;
s = s & &quot;</command>&quot;
End Sub


------------------------
ASP CODE
------------------------
<%script language=vbscript
'create a DOMDocument object
set xml=server.createobject(&quot;msxml2.domdocument&quot;)
xml.async=false

'load the POST data from the client
xml.load request

set n=xml.selectsinglenode(&quot;command/commandtext&quot;)
if n is nothing then
call responseerror(&quot;Missing command text.&quot;)
end if

set returnsdata=xm.selectsinglenode(&quot;returnsdata&quot;)

set conn=server.createobject(&quot;adodb.connection&quot;)
conn.ConnectionString = &quot;Provider=SQLOLEDB.1;Persist Security Info=false;Initial Catalog=LOANIO;Data Source=DEVSQL01;Integrated Security=SSPI;&quot;
conn.connectiontimeout=0
conn.commandtimeout=0
conn.Open

'retrieve the data
if not returnsdata then
conn.execute
else
set r=server.createobject(&quot;adodb.recordset&quot;)
r.cursorlocation=aduseclient
r.open n,conn,,adopenstatic,adlockreadonly
end if

'return the data, if required
if returnsdata then
dim xmldoc
set xmldoc=server.createobject(&quot;msxml2.domdocument&quot;)
r.save xmldoc,1
'xmldoc.load &quot;testxml.xml&quot;
response.contenttype=&quot;text/xml&quot;
response.write xmldoc.xml
end if
%>
 
if you cut and paste the above and I am not looking at a typo from your post then you have a problem in your code that would generate the above error.

You declare:
dim xttp as MSXML2.XMLHTTP

then you set:
set xhttp = NEW MSXML2.XMLHTTP

And then you set:
set xmldoc = xttp.responseXML

See the problem?
xttp has never been set to anything, hence &quot;Object variable not set&quot;

Maybe that &quot;H&quot; just found its way into your post and is not in your code-- but if it is in your code as it is spread throughout your example above you have a problem.

 
Just a suggestion . . . if you are using variables withou first declaring them, that can lead to really nasty bugs. Make sure that your code has an Option Explicit in the top of every file and then the complier will warn you. Better yet, turn in on it your options *for some reason, the default is to leave this off) and VB will automatically put it there for you. here is how . . .


1) Select Tools from the menubar
2) Go To Options
3)On the editor tab, make sure that 'Require Variable Declaration' is checked.


This may not be the only problem that you having now, but it will save you some headaches in the future.
- Jeff Marler B-)
 
Good grief! What a silly mistake! Well, I've got that fixed but now my asp page seems to be returning an empty recordset. In my VB code I am opening the POST method of the ASP page and sending it the following XML data:
<?xml version=&quot;1.0&quot;?>
<command>
<commandtext>select * from users</commandtext>
<returnsdata>True</returnsdata>
</command>

In my ASP page I am attempting to retrive the COMMANDTEXT node via the following commands:
xml.load request
set sqlcmd=xml.selectsinglenode(&quot;command/commandtext&quot;)

BUT, I don't believe that is working. Everything I've tried seems to point to the possibility that SQLCMD is never receiving the string included in COMMANDTEXT node. I have a feeling it has something to do w/ my ASP code but I do not know how to fix it.

Also, since this question seems to be a mix of VB, ASP, and XML, I'm not even sure if this is the right forum! <:(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top