ASP classic application hungs at function call - debugging

Good day!
I'm experiencing an issue with an ASP classic application we have. We were working on the SQL connection management and everything was perfect, so we deployed on another environment for the users to test and one of the ASP page hungs for 90 sec and results in:
Active Server Pages error 'ASP 0113'
Script timed out
So, I tried adding some debug code. What I used is:
Response.End
To check where it was hanging. I finally discovered that it was the new function we developed that was hanging, obviously! Here's a little extract:
Dim sqlConn
Set sqlConn = SessionConnection("SQLConnection")
set rsIDXMDL = SQLQuery(sqlConn, sQuery)
If I put a Response.End just before the call to SessionConnection(), the process stops. If I put the Response.End after the call to SessionConnection(), the page hangs for 90 sec. That made me think: "Bingo! Something inside fails!" So, just for fun, I put a Response.End at the first line of the function, like:
Function SessionConnection(SessVarName)
Response.End
[...]
I'm sure you can guess what happened!!! THE PAGE STILL HANGS!!! How is this possible?

Ideally you need to improve the code's efficiency so that it does't time out at all however if that's somehow not possible as a band aid you can try to increase the timeout:
Server.ScriptTimeout = 180
This value indicates how long, in seconds, the server will let an ASP script run until it is stopped by the server. The default value is 90 seconds.
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionTimeout = 120
conn.Open <connectionString>
Where conn is an ADODB.Connection object that is not yet open, the connectionTimeout property will indicate the amount of time, in seconds, to wait for an ASP application to initially connect to the data source. The default is 15 seconds
Set conn = CreateObject("ADODB.Connection")
conn.Open <connectionString>
conn.CommandTimeout = 120
CommandTimeout tells the server how long to wait, in seconds, for completion of any command sent to the data source. This value is editable before and after the connection has been opened. The default is 30 seconds
Hope this helps.

Related

VBS & WSH error on simple loop and cpu over usage

I have a simple script that hunts for popup boxes that are generated for website and Excel.
It works most of the time but errors out occasionlly and seemingly randomly.
The error is
line: 6
Char: 3
Error: Invalid window handle
Code: 80070578
I can't figuer out why it'll work for hours then error seemingly at random.
Also the script uses a lot of CPU if anyone could advise how to make it more efficent.
Thanks For your time
Set WshShell = CreateObject("WScript.Shell")
Do
Do
ret = WshShell.AppActivate("Message from webpage")
ret2 = WshShell.AppActivate("Microsoft Excel")
Loop Until ret = True or ret2 = True
WScript.sleep 500
ret = WshShell.AppActivate("Message from webpage")
ret2 = WshShell.AppActivate("Microsoft Excel")
If ret = True or ret2 = True Then
WScript.Sleep 200
WshShell.SendKeys("{ENTER}")
End If
WScript.sleep 500
Loop
The simple answer is VBScript is not designed to run scripts continuously.
As for what you can do the improve it, let's dissect it a little.
The outer loop is running every 500 milliseconds, which means that every half a second the script is triggered forever this is heavy for what it is doing and will likely cause heavy CPU usage the longer it runs.
Does the outer loop need to run so often, could you not increase the Sleep() from 500 to say 1000 or even 5000 to reduce the load on the CPU?
Better yet you could drop the outer loop completely and run the task using Windows own Task Scheduler which will allow you to create a scheduled task that will execute the script however often you wish. That way the script runs to completion closes releases the memory and is then run again at the next interval.

How to Get around Hard Coding the Host Session ID in vbScript or VBA code

I have novice knowledge working with PCOMM on the AS400. I have written 15 VBA scripts in Excel which calls AS400 Macros. To get the programs to work the AS400 has to be at the Login Screen and the Active Host Session MUST be set at "D". It is the Host Session that is giving me the blues. As there are many using the same PC, I never know which Host Session the AS400 will active at any point in time... sometimes "A", sometimes "B", or there may be multiple open sessions on the same screen.
The top few lines of my VBA script is below. Is there a way I can define the script to avoid using the Host Session ID ("D" in this case) so my script will work with any ID ("A" or "B", etc)
Sub APVCHDET()
Set autECLSession = CreateObject("PCOMM.autECLSession")
autECLSession.SetConnectionByName ("D")
>
enter image description here
I found this in the documentation:
Dim SessObj as Object
Dim autECLConnList as Object
Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set SessObj = CreateObject("PCOMM.autECLSession")
' Initialize the session
autECLConnList.Refresh
SessObj.SetConnectionByHandle(autECLConnList(1).Handle)
SessObj.StopCommunication()
More here. It's a little like drinking from a fire hose though.
Set SessObj = CreateObject("PCOMM.autECLSession"), in ur code, SessObj used for set which session need to be connected. regarding ur question to Jmarkmurphy, commented out the "SessObj.StopCommunication()", this has the same effect as going to the PCOMM emulator Communication menu and choosing Disconnect.
Finally regarding your original issue, error on "autECLSession.autECLOIA.WaitForAppAvailable", as mentioned at the very beginning, u have set to connect with session by using "SessObj" hence, for "autECLSession" has not been used at all to connect with any connection, that's why popup the error "The Session has not been set for this object"

Time Delay in VBScript

i want to introduce a 3 hour delay between two consecutive lines in my VB script code.
I am using the following code snippet for this:
WScript.Sleep 10800000
But I think the code is stopping for a long time, much more than 3 hours. I used 10800000 as i read time is given in milliseconds.
Please let me know my mistake and the correct way to achieve this.
Thank You!
Try something like this:
timeout = DateAdd("h", 3, Now)
Do Until Now > timeout
WScript.Sleep 200
Loop
Important This solution was provided because question was tagged excel-vba at the beginning.
I will give you different option. I imagine you have something like this at the moment:
Sub MyCurrentSub()
Dim A
A = 10
'wait 3 hour here and...
'...after 3 hours do other part of the sub
MsbBox A
End Sub
During waiting time, even if you use different option to wait (like Do...Loop) your Excel application will be limited, at least partially will not work as usually.
I would do it in this way, by creating and calling different Sub at the right moment:
Public A
Sub MyNewSub_1()
A = 10
Appication.OnTime Now + TimeValue("03:00:00"), "MyNewSub_2"
End Sub
'now you can use your Excel as usually...
Sub MyNewSub_2()
MsgBox A
End Sub
You will get the same result, Excell will be free for you to use for 3 hours during waiting time. The only think you need to remember is to- DO NOT QUIT APPLICATION. If you Quit Excel it will 'forget' to call MyNewSub_2.

Is there a way to increase the timeout value for Dynamics CRM server invocation?

I am write a simple application to test the Linq query functionality provided by CRMSDK.
My code is simple enough.
var before = DateTime.Now;
var crm = new Stub.Xrm.MyDataContext("MyCRM");
var contact = crm.contacts.FirstOrDefault();
var span = new TimeSpan(DateTime.Now.Ticks-before.Ticks);
Console.WriteLine("The name is " + contact.name);
Console.WriteLine("It took " + span.Seconds + " seconds to run this program " );
It took about one minute to run but it worked.
Then I try to query different entity such as account, I got the
Unhandled Exception: System.Net.WebException: The operation has timed out
I am suspecting this happens because I had more accounts then contacts, so it took longer to process account query. I am trying to increase the timeout value at my app.config by but didn't work.
The timeout does not happen in your application. The timeout happens on the server side. Therefore you could increase it there.
Is there a special reason why you would load all records at once and take only the first of the sequence?
You should never have a request with an unbounded result set.
If you have 500k accounts in your system, the query will return all of them (including all their filled properties).
You can increase the timeout values in the web.config of CRM.
To increase CRM timeout, you can use two approaches:
Server side
Check out this 'A time-out occurs when you import large customization files into Microsoft Dynamics CRM'
Client side
if you use service proxy as the connection scenario, you can set the Timeout property. Here is the sample:
_serviceProxy.EnableProxyTypes();
var timeout = new TimeSpan(0, 10, 0); // add 10 minutes
_serviceProxy.Timeout = timeout;
Hope this help.

vbscript return empty data

I am using vbscript .vbs in windows scheduler.
Sample code:
objWinHttp.Open "POST", http://bla.com/blabla.asp, false
objWinHttp.Send
CallHTTP= objWinHttp.ResponseText
strRESP= CallHTTP(strURL)
WScript.Echo "after doInstallNewSite: " & strRESP
Problem: blabla.asp is handling a task that need around 1-2 minute to complete.
It should return 'success' when the task completed.
But it return a empty result to the server vbs. (shorter than the normal time to complete the thing. I then go to check whether the task is completed, the answer is yes too.
I found this to happen when the task need longer time to complete.
Is this the weakness of vbs?
Help!!!
You can specify timeouts for the winhttp component:
objWinHttp.SetTimeouts 5000, 10000, 10000, 10000
It takes 4 parameters: ResolveTimeout, ConnectTimeout, SendTimeout, and ReceiveTimeout. All 4 are required and are expressed in milliseconds (1000 = 1 second). The defaults are:
ResolveTimeout: zero (no time out)
ConnectTimeout: 60,000 (one minute)
SendTimeout: 30,000 (30 secs.)
ReceiveTimeout: 30,000 (30 secs.)
So I suggest increasing the ReceiveTimeout
What is objHTTP specifically?
Looking at the target server's log, was the request received?
I can't find this in server log.
objWinHTTP is a standard protocol to send call and wait for response.
I did try using PHP and curl to do the whole process, but failed. Reason: PHP is part of the component in windows server. When come to global privilege and file folder moving, it is controlled by windows server. So I give up, and use vbs.
objWinHTTP is something act like curl in PHP.
sounds to me like the request to is taking too long to complete and the server is timing out. I believe the default timeout for asp scripts is 90 seconds so you may need to adjust this value in IIS or in your script so that the server will wait longer before timing out.
From http://msdn.microsoft.com/en-us/library/ms525225.aspx:
The AspScriptTimeout property
specifies (in seconds) the default
length of time that ASP pages allow a
script to run before terminating the
script and writing an event to the
Windows Event Log. ASP script can
override this value by using the
ScriptTimeout property of the ASP
built-in Session object. The
ScriptTimeout property allows your ASP
application to set a higher script
timeout value. For example, you can
use this setting to adjust the timeout
once a particular user establishes a
valid session by logging in or
ordering a product.

Resources