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 = "<?xml version=""1.0""?>" & vbCrLf
s = s & "<command>"
s = s & "<commandtext>select * from users</commandtext>"
s = s & "<returnsdata>True</returnsdata>"
s = s & "</command>"
End Sub
------------------------
ASP CODE
------------------------
<%script language=vbscript
'create a DOMDocument object
set xml=server.createobject("msxml2.domdocument"
xml.async=false
'load the POST data from the client
xml.load request
set n=xml.selectsinglenode("command/commandtext"
if n is nothing then
call responseerror("Missing command text."
end if
set returnsdata=xm.selectsinglenode("returnsdata"
set conn=server.createobject("adodb.connection"
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=false;Initial Catalog=LOANIO;Data Source=DEVSQL01;Integrated Security=SSPI;"
conn.connectiontimeout=0
conn.commandtimeout=0
conn.Open
'retrieve the data
if not returnsdata then
conn.execute
else
set r=server.createobject("adodb.recordset"
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("msxml2.domdocument"
r.save xmldoc,1
'xmldoc.load "testxml.xml"
response.contenttype="text/xml"
response.write xmldoc.xml
end if
%>
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 = "<?xml version=""1.0""?>" & vbCrLf
s = s & "<command>"
s = s & "<commandtext>select * from users</commandtext>"
s = s & "<returnsdata>True</returnsdata>"
s = s & "</command>"
End Sub
------------------------
ASP CODE
------------------------
<%script language=vbscript
'create a DOMDocument object
set xml=server.createobject("msxml2.domdocument"
xml.async=false
'load the POST data from the client
xml.load request
set n=xml.selectsinglenode("command/commandtext"
if n is nothing then
call responseerror("Missing command text."
end if
set returnsdata=xm.selectsinglenode("returnsdata"
set conn=server.createobject("adodb.connection"
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=false;Initial Catalog=LOANIO;Data Source=DEVSQL01;Integrated Security=SSPI;"
conn.connectiontimeout=0
conn.commandtimeout=0
conn.Open
'retrieve the data
if not returnsdata then
conn.execute
else
set r=server.createobject("adodb.recordset"
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("msxml2.domdocument"
r.save xmldoc,1
'xmldoc.load "testxml.xml"
response.contenttype="text/xml"
response.write xmldoc.xml
end if
%>