Connection file
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "abc","ID","Password"
conn.commandtimeout=120
Set RS = Server.CreateObject("ADODB.RecordSet")
rs.activeConnection = Conn
%>
Classic ASP file
<%response.buffer = true%>
<%Response.Expires = 0%>
<!-- #include file="functions.asp" -->
<% Response.Write session("RequestID")%>
<%if session("ValidLogon") <> "true" then
if request("FromEmail") = "True" then
SetSessVar()
else%>
<%response.redirect "Default.asp"
end if
end if%>
<html>
<body>
<%rs.Source = "SELECT * from tblRequests WHERE RequestID = " & request("requestID")
rs.Open
session("RequestID") = rs("requestid")
if rs("RequestType") = "O" then
response.clear
If request("Tag") = "Change" then
response.redirect "abc.asp#change"
else
response.redirect "abc.asp?From=" & request("From")
end if
else
response.clear
If request("Tag") = "Change" then
response.redirect "editinternal.asp#change"
else
response.redirect "editinternal.asp?From=" & request("From")
end if
end if
rs.close%>
</body>
</html>
I have checked the classic asp page and it looks like there is an error in syntax inside "Body" tag. I don't know anything about it.
It is giving internal server error 500.
In Connection File you are missing Set on rs.activeConnection = Conn as you are setting an object reference to the ADODB.Connection object instance not passing a connection string.
'Object instances require Set
Set rs.activeConnection = Conn
Please make sure that you configure your site to send the detailed error messages to the client
This describes how:
Show detailed errors
I would guess that your connection "abc"/"ID"/"Password" has to be a real connection. It seems that you just wrote something to see what happens. It could also be the "functions.asp" file that you are including. Does that file exist, what does it contain?
Please post back your detailed error messages, then we can help you better.
Before referencing to the recordset you should check if the recordset contains any records like:
If not rs.eof then
Session("reqestid") = rs("reqestid")
....
End If
Just want to add one trix here, try add these 2 lines right after the body tag
Response.Write "<br>For the sake of debug"
Response.Flush
If you have buffering on, this sometimes writes out the error instead of throwing out error 500. Helps me often.
Related
I'm trying to pull data from an NHS API using a little bit of classic ASP (all I know I'm afraid) but am struggling to successfully pass the subscription key to the API.
The instructions are as follows:
Pick a page on the NHS website, for example: https://www.nhs.uk/conditions/acne.
Make a note of the path, for example: conditions/acne.
Using a tool such as curl, Postman or your web browser, make a GET request to https://api.nhs.uk/content/acne with a valid subscription key subscription‑key: {subscription-key} in the request header.
You’ll receive a JSON response structured using schema.org and the fields for this are explained in the following documentation....
From https://developer.api.nhs.uk/documentation/content-api
So, I wrote the following...
<%
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
xml.Open "GET", "https://api.nhs.uk/conditions/abdominal-aortic-aneurysm-screening/", False
on error resume next
xml.setRequestHeader "subscription‑key", "MY-API-KEY-HERE"
xml.setRequestHeader "Content-Type", "application/json"
xml.setRequestHeader "Accept", "application/json"
xml.Send
Response.Write "<h1>The HTML text</h1><xmp>"
Response.Write xml.responseText
Set xml = Nothing
%>
This just gives me the following response:
{ "statusCode": 401, "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API." }
They have example scripts in 5 different languages but not ASP or even ASP.NET
Any ideas what I can try to get this working?
Thanks
EDIT
Trying the method suggested here How can I post data using cURL in asp classic? ...
<%
Dim http: Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Dim url: url = "https://api.nhs.uk/conditions/abdominal-aortic-aneurysm-screening/"
'Dim data: data = "something=this" - took this out as its a querystring for POST
With http
Call .Open("GET", url, False)
'Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call .SetRequestHeader("subscription‑key", "MY-API-KEY-HERE")
'Call .Send(data) <- the data was the querystring, so not relevant here
Call .Send()
End With
If Left(http.Status, 1) = 2 Then
'Request succeeded with a HTTP 2xx response, do something...
Else
'Output error
Call Response.Write("Server returned: " & http.Status & " " & http.StatusText)
End If
%>
This gives me Invalid procedure call or argument: 'SetRequestHeader'
EDIT WITH SOLUTION
Working code with hyphen issue fixed...
<%
Dim http: Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Dim url: url = "https://api.nhs.uk/conditions/abdominal-aortic-aneurysm-screening/"
With http
Call .Open("GET", url, False)
Call .SetRequestHeader("subscription-key", "MYKEYHERE")
Call .Send()
End With
If Left(http.Status, 1) = 2 Then
'Request succeeded with a HTTP 2xx response, do something...
Response.Write http.responseText
Else
'Output error
Call Response.Write("Server returned: " & http.Status & " " & http.StatusText)
End If
%>
Thanks Lankymart!
Tried your take on the duplicate example and it returned
Invalid procedure call or argument: 'SetRequestHeader'
This puzzled me as that code had been tested before and work fine so what changed?
So I dug into the SetRequestHeader method calls.
Turns out the error only occurs on this line;
Call .SetRequestHeader("subscription‑key", "MY-API-KEY-HERE")
In the end, removed subscription‑ from the header name and it worked without causing a compilation error.
That led me to check the hyphen in the code using Asc("‑") and comparing that with a standard hyphen and sure enough they are different.
<%
Response.Write Asc("‑") & "<br />" 'From the code
Response.Write Asc("-") & "<br />" 'Standard hyphen
%>
Output:
-15454
45
Replaced the character with a standard hyphen the error has gone and the code runs returning;
Server returned: 401 Unauthorized
my code where I try to login into the website automatically. But it keeps on throwing
The object is lost connection from its client
Dim IE
set IE = WScript.CreateObject("InternetExplorer.Application")
IE.Visible = true
Call IE.navigate("http://finrpa:8080/controlroom/")
Do While IE.ReadyState <> 4
WScript.Sleep 10
Loop
IE.Document.all.username-inputEl.Value = "parthiban.nadar#thirdware.com"
IE.Document.all.password-inputEl.Value = "Thirdw#re1"
Call IE.Document.all.gaia_loginform.submit
Set IE = Nothing
What line the exception is thrown?
I see at least one problem with the script. Because the control names contain dashes, they should be strings. So, instead of
IE.Document.all.username-inputEl.Value = "parthiban.nadar#thirdware.com"
IE.Document.all.password-inputEl.Value = "Thirdw#re1"
should be
IE.Document.getElementById("username-inputEl").Value = "parthiban.nadar#thirdware.com"
IE.Document.getElementById("password-inputEl").Value = "Thirdw#re1"
I have a file header.asp that has an server side include head.asp. Inside head.asp my connection to my database is created and is accessible from the header.asp file and pages that use the header.asp file as an server side include (in this case my core.asp file). Inside core.asp I have the following:
if request.querystring("page") = "" then
response.write("<p>No data to load</p>")
else
page = request.querystring("page")
set fso = createobject("scripting.filesystemobject")
FileName = "../Pages/" & page & ".asp"
if fso.FileExists (server.mappath(FileName)) then
Server.Execute(FileName)
else
response.write("<p>Could not validate page. Try again.</p>")
end if
end if
This executes just fine and the proper page renders inside the core.asp file. My issue, is that the connection string (from head.asp) is not available to the file being called from Server.Execute. Thus, I cannot run database queries, etc. on this page unless I were to instantiate the object anew. Is there any way to use the object created?
If I have not explained this properly, I will expound as I am able given my intermediate experience level.
As a follow up to answer #1, if I've followed the logic correctly, I'm attempting to create the connection object at the application level (global.asa):
Sub Application_OnStart()
dim oConn, connectstr
set oConn = Server.CreateObject("ADODB.Connection")
connectstr = "Driver={MySQL ODBC 3.51 Driver};SERVER=theServer; DATABASE=theDatabase; UID=theUserID; PWD=thePassword"
oConn.ConnectionTimeout = 5
oConn.Open connectstr
Application("con") = oConn
end Sub
</script>
Attempting to access the object like so from my page that includes the global.asa as an IIS:
qryAdmin = "select * from table"
set rsAdmin = Application("con").execute(qryAdmin)
The results are the same. I receive the "Object required" error. Any glaring errors that could be causing this?
Assign this object to a session variable and you can access it from any page you like...
Session("MyConnectionObj")= CONN
CONN is your instantiated connection object on the page where you instantiate your connection originally. And in your executed file just call
set NewCONN=Session("MyConnectionObj")
RS.Open strSql ,NewCONN,1,1
where strSql is your SQL, RS is your recordset etc... Obviously if you calling the stored procedure, it will look slightly different but you get the point.
Edited to show that object have to be declared and set before one using it. As I see at least one "expert" did not know that.
Edited base on comments from Window Frog:
did you try it like that:
<%
if request.querystring("page") = "" then
response.write("<p>No data to load</p>")
else
page = request.querystring("page")
set fso = createobject("scripting.filesystemobject")
FileName = "../Pages/" & page & ".asp"
if fso.FileExists (server.mappath(FileName)) then%>
<!--#include file="<%=FileName %>" -->
<% else
response.write("<p>Could not validate page. Try again.</p>")
end if
end if
%>
This is my fort post on stackoverflow. I have searched many similiar Q&A's on this site but my conditions seem a bit different. here is my vbscript code:
------------ code snippet ---------------
xmlurl = "songs.xml"
set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.loadXML(xmlurl)
if xmlDoc.parseError.errorcode<>0 then
'error handling code
msgbox("error! " & xmlDoc.parseError.reason)
end if
------------ end code snippet ---------------
XML:
<?xml version="1.0" encoding="UTF-8"?>
<nowplaying-info-list>
<nowplaying-info mountName="CKOIFMAAC" timestamp="1339771946" type="track">
<property name="track_artist_name"><![CDATA[CKOI]]></property>
<property name="cue_title"><![CDATA[HITMIX]]></property>
</nowplaying-info>
<nowplaying-info mountName="CKOIFMAAC" timestamp="1339771364" type="track">
<property name="track_artist_name"><![CDATA[AMYLIE]]></property>
<property name="cue_title"><![CDATA[LES FILLES]]></property>
</nowplaying-info>
<nowplaying-info mountName="CKOIFMAAC" timestamp="1339771149" type="track">
<property name="track_artist_name"><![CDATA[MIA MARTINA]]></property>
<property name="cue_title"><![CDATA[TOI ET MOI]]></property>
</nowplaying-info>
</nowplaying-info-list>
I also tried removing the first line in case maybe UTF-8 was not compatible with windows (saw some posts about this), but I still got the same error. I also tried unix2dos and vice versa in case there were carriage return issues (hidden characters embedded in the xml). I just can't seem to figure out what's wrong. It's such a simole XML file. I could parse it in a few minutes using perl regex but I need to run this script on windows so using vbscript. I use the same technique to parse XML from other sources without any issues. I cannot modify the XML unfortunately, it is from an external source.
I have this exact same error on both my Windows Vista home edition and Windows Server 2008. I am running the vbscript from the command line for testing so far (ie not in ASP).
Thanks in advance,
Sam
xmlDoc.loadXML() can load an XML string. It cannot retrieve a URL.
Use an XMLHTTPRequest object if you need to make an HTTP request.
Function LoadXml(xmlurl)
Dim xmlhttp
Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
xmlhttp.Open "GET", xmlurl, false
' switch to manual error handling
On Error Resume Next
xmlhttp.Send
If err.number <> 0 Then
WScript.Echo xmlhttp.parseError.Reason
Err.Clear
End If
' switch back to automatic error handling
On Error Goto 0
Set LoadXml = xmlhttp.ResponseXml
End Function
Use like
Set doc = LoadXml("http://your.url/here")
Three addition remarks:
(1) As .parseError.reason tends to be cryptic, it pays to include its .srcTxt
property (and the parameter to .loadXml):
Dim xmlurl : xmlurl = "song.xml"
Dim xmlDoc : Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.loadXML xmlurl
If 0 <> xmlDoc.parseError.errorcode Then
WScript.Echo xmlDoc.parseError.reason, "Src:", xmlDoc.parseError.srcText
Else
WScript.Echo "surprise, surprise"
End if
output:
Invalid at the top level of the document.
Src: song.xml
Of course, writing a Function/Sub that takes all properties of .parseError
into account and using that always, would be even better.
(2) To load a file or URL, use .load:
Dim xmlDoc : Set xmlDoc = CreateObject("Microsoft.XMLDOM")
Dim xmlurl
For Each xmlurl In Array("song.xml", "http://gent/~eh/song.xml", "zilch")
xmlDoc.async = False
if xmlDoc.load(xmlurl) Then
With xmlDoc.documentElement.firstChild
WScript.Echo xmlurl _
, .tagName _
, .firstChild.tagName _
, .firstChild.text
End With
Else
WScript.Echo xmlurl, xmlDoc.parseError.reason, "Src:", xmlDoc.parseError.srcText
End if
Next
output:
song.xml nowplaying-info property CKOI-ÄÖÜ
http://gent/~eh/song.xml nowplaying-info property CKOI-ÄÖÜ
zilch The system cannot locate the object specified.
Src:
(3) Using the DOM avoids all encoding problems (that's why I put some
german umlauts into 'your' file - which even made it to the DOS-Box output)
and makes RegExps (even Perl's) a second best choice.
It's been a day I've cracked my head to solve this....I've googled for solutions but none of it resolve my issue...
The code is like this:
Private Sub guh()
Dim oConn As Connection
Dim Record As Recordset
Dim SqlStr As String
SqlStr = "select * from dbo.Msg_History where Client_ID='2' AND Update_Msg='4'"
Set oConn = New Connection
With oConn
.CursorLocation = adUseClient
.CommandTimeout = 0
.Open "Provider=SQLOLEDB;Server=127.0.0.1;Initial Catalog=Table_Msg;UID=Admin;PWD="
End With
Set Record = oConn.Execute(SqlStr)
If IsNull(Record) Then
MsgBox "There are no records"
Else
MsgBox "There are records"
End If
oConn.Close
Set oConn = Nothing
End Sub
The sql statement is returning null recordset ..when i run the code...it always go to the "else" condition which is the line MsgBox "There are records"
I've tried change the line : If IsNull(Record) Then
to
If IsNull(Record.Fields(0).Value) Then
but then it throws an error like this:-
error: Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record.
I've checked http://support.microsoft.com/kb/304267 and use eof and bof to the condition...n still get the same error..
please anyone help me...
I would use something like this:
' returns true if there is non empty recordset
Function isRSExists(rs) AS boolean
' has to exists as object
If Not rs Is Nothing Then
' has to be opened with recordset (could be empty)
If rs.State > 0 Then
' has to have some records
If Not rs.EOF Then
isRSExists = true
End If
End If
End If
End Function
Change this
If IsNull(Record) Then
to
If Record.RecordCount = 0 Then
I think you can test for if not Record.Eof.
If I recall correctly (it's been a long time), it only works with one type of cursor, I think it should be adUseServer. (EDIT No, it's actually RecordCount which has this problem)
I'll try and dig out some old code to check.
Thanks for the replies guys :D ...will test it later anyway...I havent's tested all of your suggestions at the time I'm posting this reply...I tested this: –
If Record.BOF And Record.EOF Then
and this works...