| No more Remote Scripting and workaround fails 2nd connection | |
|
Author | Message |
---|
wilderness Member
Posts : 7 Join date : 2011-04-08
| Subject: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:38 am | |
| Can someone show me how to get a second recordset object to work within ASP page VB Script function? Apparently, the latest Java JRE 6 updates (22, 23, and 24) cause remote scripting using standardized rs.asp and rs.htm code to fail and it appears that Oracle has no plans to fix this bug. I have tried to do a workaround by trying to call VB Script function locally to filter a second <select> pull-down list based on the actual selection from the first list. However when I do either the recordset object is out of scope or trying to set up a second connection object in the code is not acceptable either. See below code where the object connection "Open" function, in include file, points to a SQL Server 2005 database. The second Recordset object, "oRsA" is either out of scope or when uncommenting the ADODB.Connection it fails with a "Type Mismatch" error on the Connection Open even if I create a second "oConn2" and open function pointing to the same connection string. - Code:
-
<%@LANGUAGE=VBScript%> <!-- #INCLUDE file="../Includes/VBScript1.vbs" --> <!-- #INCLUDE file="../Includes/Constants.inc" --> <!-- #INCLUDE file="Constants.inc" --> <%
Response.CacheControl = "no-cache" Response.AddHeader "Pragma", "no-cache" Response.Expires = -1 lHelp = true If NetworkID() <> Session("NetworkID") Then Response.Redirect("Timeout.ASP") End If
IF Month(Now) > 6 AND Month(Now) < 9 Then dFYStart = PriorFiscalStart("01/01/" & Year(Now)) Else dFYStart = FiscalStart() End If
Set oConn = CreateObject("ADODB.Connection") Val_Open = open_oConn() Set oRs = CreateObject("ADODB.RecordSet") oRs.ActiveConnection = oConn oRs.Source = "SELECT * FROM TravelerView WHERE Authorized = '" & Session("NetworkID") & "' ORDER BY Last, First" oRs.Open
%> <html> <head> <META name=VI60_defaultClientScript content=VBScript>
<title>DCFS Travel Vouchers</title> <link rel="stylesheet" type="text/css" href="Global.css" /> <SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript> <!--
Function ReasonList(sndTravelCategory) 'on error resume next
dim theform 'debug set theform = document.forms("trip") 'debug theForm.txtComment.value = ("Starting ReasonList function for category: " & sndTravelCategory) 'Set oConn = CreateObject("ADODB.Connection") 'Val_Open = open_oConn() Set oRsA = CreateObject("ADODB.RecordSet") oRsA.ActiveConnection = oConn theForm.txtComment.value = "OrsA ActiveConnection set to oConn!" oRsA.Source = "SELECT TravelReason from ReasonForTravel WHERE TravelCategory = '" & sndTravelCategory & "' ORDER BY TravelReason" theForm.txtComment.value = "oRsA source set to SQL statement: " 'debug oRsA.Open ReasonList = " , " theForm.txtComment.value = "starting do while oRs Opened " 'debug
do while not oRsA.EOF ReasonList = ReasonList & Trim(ors.fields("TravelReason").value) & ", " oRsA.MoveNext loop
theForm.txtComment.value = ("List: " & getReasonList) 'debug
oRs.Close set oRs = nothing
Return ReasonList End Function . . .
|
|
| |
WakeUpCall Member
Posts : 14 Join date : 2011-03-09
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:39 am | |
| Well, Remote Scripting was deprecated by Microsoft in 2002. - Code:
-
RDS: Remote Data Services (RDS) is a proprietary Microsoft mechanism for accessing remote ADO Recordset objects across the Internet or an Intranet. RDS is deprecated; no major feature enhancements have been made to RDS since MDAC 2.1. Microsoft has released the .NET Framework, which has extensive SOAP capabilities and replaces RDS components.
So it's probably long past the time you should get away from it. Anyway, your problem is that your FUNCTION there is *NOT* a server-side function! It is executing IN THE BROWSER: <SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript> So you can *NOT* share *ANY* objects or functions or anything else with your ASP code. You need to essentially clone all the ASP code to client-side equivalents. You should also be aware that using ADO objects in the browser means that (a) the user *MUST* mark the site where the page is coming from as a TRUSTED site and (b) even then the user will get a warning and a request to allow the unsafe code to run in the browser. Not to mention, of course, that the code will only run in MSIE browsers. In other words, this is a solution that is only (barely) viable for inTRAnet situtations. If that's your case, then you can probably make it work. *************** But the way way better solution for something like this is to learn to use AJAX. It avoids all the problems mentioned above. It works in all browsers. Even before AJAX came along, I was doing the equivalent using hidden frames and iframes. And that's another possible route for you. I think using ADO objects in the browser is, even in the not-very-long-run, a mistake. Even if you manage to make it work. |
|
| |
wilderness Member
Posts : 7 Join date : 2011-04-08
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:39 am | |
| Thanks for your reply. I inheirited this app without knowing a thing about ASP pages and espcially doing server side scripting as I have only used client jscript with my .NET apps and all server side code in C#. What exactly delineates a server vbscript from a client script? Something I read mentions placing the connection code inside of <% %> tags to force it run on the server, but I belive that is what you are talking about as not being way to go. What do you suggest as the simplest solution to get this app working so it doesn't have to given a highest priority for a rewrite in .NET (will still get done eventually)? |
|
| |
WakeUpCall Member
Posts : 14 Join date : 2011-03-09
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:40 am | |
| Server-side script is *EITHER* enclosed in <%...%> *OR* in <script runat="server">...</script> tags. There are subtle differences in the two, but for the most part they are equivalent. When a <script> tag *lacks* the runat="server", it becomes client-side and runs in the browsers. ************ Do you understand AJAX? If so, I would think that would be the most straightforward and quickest solution. It is not too difficult. Look here: http://www.w3schools.com/asp/asp_ajax_intro.aspThe other alternative would be to simply do it all server side in a single page by having the page post back to the server when the first <select> is changed. The server could notice the change and send everything back to the client with the second <select> in place. |
|
| |
wilderness Member
Posts : 7 Join date : 2011-04-08
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:41 am | |
| Your answer on the other page cleared up the big mystery for me of why I couldn't call a server function interactively within the same page. I am try to apply the AJAX code to do what the remote scripting used to do and expect to have a full solution in a day or two! THANK YOU VERY MUCH! |
|
| |
wilderness Member
Posts : 7 Join date : 2011-04-08
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:41 am | |
| Old Pendant, Now I am having problems with the Ajax code, from which I can't seem to get past a 404 status. I have the following JScript calling a "getTravelReasons.asp" page: - Code:
-
<SCRIPT LANGUAGE="Javascript">
//var serverURL = "\getTravelReasonList.asp"; //var aspObject;
function LimitReasonData(TravelCategory) { //Lets try a little AJAX code to get this to work!!! if (TravelCategory.length==0) { document.getElementById("lblErrorMsg").innerHTML="Category Not Selected!"; return; } if (window.XMLHttpRequest) { //code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { //code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var result = xmlhttp.responseText; fillReason(result); } else { errorCallBack(xmlhttp); } }
xmlhttp.open("POST","getTravelReasons.asp?q=" + TravelCategory,true); xmlhttp.send();
//var co = RSExecute(serverURL,"getReasonList",sndTravelCategory,fillReasonList,errorCallBack,"RSExecute"); }
function fillReasonList(co) { var reasonArray = co.value.substring(0,co.value.length).split(", "); optionsTravelReason = document.getElementById("cboTravelReason") document.Trip.cboTravelReason.options.length=0; document.Trip.cboTravelReason.selectedIndex = -1;
for (i in reasonArray) { document.Trip.cboTravelReason.options[document.Trip.cboTravelReason.options.length]= new Option(reasonArray[i],reasonArray[i]); } }
function errorCallBack(co) { alert("ERROR_CALLBACK\n\n" + "status = " + co.status + "\n\n" + "state = " + co.readyState + "\n\n" + "data = " + co.responseText); }
//--> </script>
- Code:
-
<%@ Language=VBScript %> <!-- #INCLUDE file="Constants.inc" -->
<% msgbox("we are inside the getTravelReasons.asp file") Response.expires=-1 sql="SELECT TravelReason from ReasonForTravel WHERE TravelCategory =" sql=sql & " '" & Request.querystring("q") & "' ORDER BY TravelReason" Set oConn = CreateObject("ADODB.Connection") oConn.Open Open_Connection() Set oRs = CreateObject("ADODB.RecordSet") oRs.ActiveConnection = oConn
oRs.Source = sql oRs.Open BuildList = " , " do while not ors.EOF BuildList = BuildList & Trim(ors.fields("TravelReason").value) & ", " ors.MoveNext loop Response.Write(BuildList)
oRs.Close set oRs = nothing
%>
I created my code from the Ajax examples you directed me towards. However, I am not sure what is throwing the 404 status. Is it the name of the asp page or the query string in the xmlhttp.open statement or is it caused by the code in the getTravelReasons.asp page itself? The resonse text is just a lenthy general description of a 404 error and provides no insight in what is wrong. |
|
| |
wilderness Member
Posts : 7 Join date : 2011-04-08
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:42 am | |
| I found the cause of the 404. It was because my IDE saved the new .asp page it to a sub-directory and in the Project Explorer it looked correct ... until scrolling it over!:lol:
Now I am getting an Object Expected error, which I suppose is not processing the connection/recordset CreateObjects correctly. Since it won't let me embed a msgbox (creates a permission error?), how can I debug the VBScript of the called asp page, when it has no html of its own? |
|
| |
wilderness Member
Posts : 7 Join date : 2011-04-08
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:42 am | |
| OLD PENDANT,
Never mind! I have resolved all the issues and the AJAX approach works like a charm. Again, THANK YOU VERY MUCH FOR YOU ASSISTANCE! |
|
| |
WakeUpCall Member
Posts : 14 Join date : 2011-03-09
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection Sun May 01, 2011 3:43 am | |
| One minor error here: - Code:
-
xmlhttp.open("POST","getTravelReasons.asp?q=" + TravelCategory,true); xmlhttp.send();
Since you are *NOT* sending any POST data (if you were, it would be the argument to the send( ) call), you should really specify "GET" instead of "POST". ASP is sloppy enough that it doesn't care. Other server-side systems might have barfed on that. Just something to keep in mind for future reference. Glad you got it all worked out! Good work, starting from scratch. |
|
| |
Sponsored content
| Subject: Re: No more Remote Scripting and workaround fails 2nd connection | |
| |
|
| |
| No more Remote Scripting and workaround fails 2nd connection | |
|