Database Editing in Session OnEnd Classic ASP - asp-classic

I was Creating a website in Classic ASP Project, having a Logout feature.
I want to access the login database and make changes, when the session ends. The coding is something like:
In global.asa :
Sub Session_OnEnd()
Set studcon = Server.CreateObject("ADODB.Connection")
studcon.Open "Provider = Microsoft.JET.OLEDB.4.0;Data Source = E:\mailfan.mdb"
Set studrec = Server.CreateObject("ADODB.Recordset")
studrec.Open "login", studcon, 1, 3
studrec.movefirst
found = 0
Do While studrec.EOF or found = 1
If studrec("ID") = Session("uid") Then
studrec("log") = 0
studrec.Update
End If
studrec.movenext
Loop
studrec.close
studcon.close
Set studrec = Nothing
Set studcon = Nothing
End Sub
But Even After Session.Abandon the value of log field Remains the same (It is 1 when session's active).
Small Update: I tried to google it, and did recieve a very similar link having the same question: http://www.justskins.com/forums/problem-with-global-asa-77015.html
But the code is the same as suggested by Aaron Bertrand in the above link. Is it due to IIS 8.0? Because I would be Running it on Win XP sp3 IIS 6. And I Do require it to work there.

I can't see an SQL query anywhere in your code. If you're intent on using a recordset for your update then in place of
studrec.Open "login", studcon, 1, 3
you should have something like
studrec.Open "select * from login", studcon, 1, 3
This assumes that your database table is called "Login"
Using a recordset is actually an over complex means of doing all this though, An Update query should suffice. You could remove all your code from
Set studrec = Server.CreateObject("ADODB.Recordset")
to
studrec.close
and replace it with
studcon.Execute("UPDATE Login set log = 0 where id = " & Session("uid"))

Related

Scroll to the end of the page in SAP GUI

I'm trying to automate my SAP GUI until the end of the page and I got the code below from this site https://www.appsloveworld.com/vba/200/144/algorithm-for-finding-end-of-a-list-sap-gui
I only changed the text after findById but I get this error at the line which changes verticalScrollbar.Position:
object doesn't support this property or method
Any ideas on how to solve that?
Do While Not blank
If session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").Text = "" _
Then blank = True
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").verticalScrollbar.Position = i
i = i + 1
Loop

How can I clear all the SAP GUI fields when I open a T-Code?

When I open a T-Code from SAP GUI, some of the fields are pre-populated from past queries. Is it possible to enter a T-Code and all the fields in the next window to be forced blank?
I develop scripts for SAP GUI and run into problems if fields already have content from prior queries.
The history cannot be disabled user-wise. Period.
Either all or nobody.
If you want to disable the history go to SAPgui options into Local data setting
The history in Windows is a simple Access MDB file but it is password-protected, so you may try to crack it and delete only your user lines but it is a bunch of work.
However, I guess the history that makes you crazy is not what I described above, but SPA/GPA parameters. Check it first
You can empty some fields with :
""
session.findById("wnd[1]/usr/ctxtRMMG1_REF-BWTAR").Text = ""
But doesn't work all the time...
My method for this is to loop through all the fields (and recursively on all children elements) and set the text value of them to an empty string.
On read-only fields it throws an error and this is why "On Error Resume Next" is necessary.
Sub Start_Clearing()
'setup SAP
If Not IsObject(SAPApplication) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPApplication.Children(0)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject Session, "on"
WScript.ConnectObject SAPApplication, "on"
End If
Dim UserArea As Object
Set UserArea = Session.findByID("wnd[0]/usr")
Clear_Fields UserArea
End Sub
'_______________________________
Sub Clear_Fields(Area As Object)
Set SAPApplication = GetObject("SAPGUI").GetScriptingEngine
Dim Obj As Object
Dim NextArea As Object
On Error Resume Next
For i = 0 To Area.Children.Count - 1
Set Obj = Area.Children(CInt(i))
If Obj.ContainerType = True Then
If Obj.Children.Count > 0 Then
Set NextArea = SAPApplication.findByID(Obj.ID)
Clear_Fields NextArea
End If
End If
Obj.Text = ""
Next i
End Sub

Time management of a script asp

within a page ASP (classic) I have a function that connects to the server via XMLHTTP to google to get the time and distance between two points.
I noticed that sometimes my server makes this request very slowly sending the script out and blocking the page.
I would therefore ask you.
If I change the attached script to say
if the execution time exceeds five seconds then stops the script
function GooDistInd(origine,destintario)
Set objxml = Nothing
' Dichiaro le variabili che mi servono nello script
Dim file, objXmlHttp, objXmlDom, distanza, cognome, i
'http://maps.google.com/maps/api/directions/xml?origin=40.7143528,-74.0059731&destination=40.7035458,-74.21607971&sensor=false
file = "http://maps.googleapis.com/maps/api/directions/xml?origin="& origine &"destination="&destintario &"&sensor=false"
Set objXmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
objXmlHttp.Open "GET", file, False
objXmlHttp.Send
Set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
objXmlDom.async = False
objXmlDom.loadXML(objXmlHttp.responseText)
Set tempo = objXmlDom.getElementsByTagName("leg/distance/value")
i = 0
For i = 0 To tempo.length - 1
distanza=tempo(i).Text
exit for
Next
GooDistInd =distanza
end function
If you want to stop the script completely you could use
Server.ScriptTimeout = 5
You could also use the timeut property of the Microsoft.XMLHTTP object and set it to 5000 ms. In this case you could work with on error resume next and check if an error occurred, so you could give back a significant error message to you users

StackoverflowException while in prod on IIS

I have a serious issue trying to put my Web Application into production.
My application is coded in VB.Net (With Visual Web Developer 2010), and the environment of production is a virtual machine with Microsoft Server 2008 R2, and IIS 7.5, the application is running with Asp.net 4.0. I tried also on my own computer (Windows 7), where I installed IIS, and the same bug occurs.
To limit the charge on SQL server, I put into session a list of rights, which is loaded each time the user wants to have access to any page.
The bug occurs exactly when this list contains more than 178 objects. At 178, the session is created and the page is correctly executed ; but when I add a 179th element or more (and I tried with different elements, so this can't come from the elements themselves), the page just don't execute correctly the code and IIS crash...
It seems that when there is more than 179 elements in this list, IIS just recycle the App, and so, the session is lost...
When I debug the application with Visual Web Developer, it is running well, without bug. But when I try to put it into production, that bug occurs. So, this seems to be linked with IIS.
Another problem is that when IIS recycle my App, it doesn't create any log file. So I have nothing more precise to give you.
I need help to find a solution to this problem. I try for a week, and I found nothing... this is driving me crazy... If someone has any idea or need more information, please tell me, so I can dig deeper...
Thanks to everyone.
EDIT :
I tried something else, I bypassed the sessions, and now, the rights are directly charged from SQL. The problem still occurs. So, it doesn't come from sessions, but SQL.
So, I wonder if there is any limit while doing requests on SQL.
But SQL doesn't seems to have any problem with request that return 3000 elements, and when it returns 179 elements with a lot of joins, it just crash... Well, I have no idea what to do or where search for a solution...
EDIT2 :
But, like I said, the problem doesn't occurs when I try execute the code from Visual Web developer. And, with it or in production environment, it's the same SQL server that execute de SQL requests... So, the problem can't come from SQL finally...
EDIT3 :
I finally found something. In the Windows logs, I have a StackOverflowException... What happy news ! (And we are on stackoverflow.com, is that linked? xD).
EDIT4 :
Here is the error from the windows log. Maybe it can help anyone.
Nom du journal :Application
Source : Windows Error Reporting
Date : 29/04/2014 11:53:11
ID de l’événement :1001
Catégorie de la tâche :Aucun
Niveau : Information
Mots clés : Classique
Utilisateur : N/A
Ordinateur : SRVWEB.DOMMH01.local
Description :
Récipient d’erreurs , type 0
Nom d’événement : CLR20r3
Réponse : Non disponible
ID de CAB : 0
Signature du problème :
P1 : w3wp.exe
P2 : 7.5.7601.17514
P3 : 4ce7afa2
P4 : System.Core
P5 : 4.0.30319.18408
P6 : 5231116c
P7 : 1197
P8 : 0
P9 : System.StackOverflowException
P10 :
Fichiers joints :
Ces fichiers sont peut-être disponibles ici :
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_w3wp.exe_e41148f8d4e7fcf353a2d93bfe4367a48b981de2_0a6131b2
Symbole d’analyse :
Nouvelle recherche de la solution : 0
ID de rapport : 125b520d-cf84-11e3-912f-00155dc81602
Statut du rapport : 4
EDIT 5 :
I put here the piece of code where I take the rights with LINQ to SQL. I don't think this will be really helpful, but there it is...
A right contains a Username, the id of the rights, the id of a family (a family is a set of "objects"), and a place. So finnaly, I get a list of "Object/Place" associated with rights for a specified user... So I can limit the access for only some "object/place" for each user.
Another thing is the familyJoker, and the placeJoker. When a right is associated with a placeJoker, wee add to the rights of this user any object/place where the object is in the family. It's the same when the family is the familyJoker. Finally, if family and place are both joker, we add all the combinations possible(the combinations possible are in the objectPlace table)
This is the code :
Public Shared Function getListeDroitsUtilisateurSession(ByVal username As String) As List(Of DroitsUtilisateurSession)
Dim db As SINDIDB = New SINDIDB
Dim familleJoker As String = FamilleMetier.famille_Joker
Dim lieuJoker As String = Lieu.lieu_Joker
Dim requeteSansJoker = From d In db.DroitsUtilisateurs
Where d.Utilisateur = username
Join r In db.Roles
On d.ID_Role Equals r.ID_Role
Join oif In db.ObjetsInFamilleMetiers
On d.ID_Famille Equals oif.ID_Famille
Join f In db.FamilleMetiers
On oif.ID_Famille Equals f.ID_Famille
Where (Not f.Nom_Famille = familleJoker)
Join ol In db.ObjetLieux
On oif.ID_Objet Equals ol.ID_Objet
Where (d.ID_Lieu = ol.ID_Lieu)
Join l In db.Lieux
On ol.ID_Lieu Equals l.ID_Lieu
Where (Not l.Valeur_Lieu = lieuJoker)
Select New DroitsUtilisateurSession With {.Role = r, .ObjetLieu = ol}
Dim requeteFamilleJoker = From d In db.DroitsUtilisateurs
Where d.Utilisateur = username
Join r In db.Roles
On d.ID_Role Equals r.ID_Role
Join f In db.FamilleMetiers
On d.ID_Famille Equals f.ID_Famille
Where (f.Nom_Famille = familleJoker)
From oCross In db.Objets
Join ol In db.ObjetLieux
On oCross.ID_Objet Equals ol.ID_Objet
Where (d.ID_Lieu = ol.ID_Lieu)
Select New DroitsUtilisateurSession With {.Role = r, .ObjetLieu = ol}
Dim requeteLieuJoker = From d In db.DroitsUtilisateurs
Where d.Utilisateur = username
Join r In db.Roles
On d.ID_Role Equals r.ID_Role
Join l In db.Lieux
On d.ID_Lieu Equals l.ID_Lieu
Where (l.Valeur_Lieu = lieuJoker)
Join oif In db.ObjetsInFamilleMetiers
On d.ID_Famille Equals oif.ID_Famille
From lCross In db.Lieux
Join ol In db.ObjetLieux
On oif.ID_Objet Equals ol.ID_Objet
Where (lCross.ID_Lieu = ol.ID_Lieu)
Select New DroitsUtilisateurSession With {.Role = r, .ObjetLieu = ol}
Dim requeteFamilleEtLieuJoker = From d In db.DroitsUtilisateurs
Where d.Utilisateur = username
Join r In db.Roles
On d.ID_Role Equals r.ID_Role
Join f In db.FamilleMetiers
On d.ID_Famille Equals f.ID_Famille
Where (f.Nom_Famille = familleJoker)
Join l In db.Lieux
On d.ID_Lieu Equals l.ID_Lieu
Where (l.Valeur_Lieu = lieuJoker)
From olCross In db.ObjetLieux
Select New DroitsUtilisateurSession With {.Role = r, .ObjetLieu = olCross}
Dim requeteTotale = requeteSansJoker.Union(requeteFamilleJoker).Union(requeteLieuJoker).Union(requeteFamilleEtLieuJoker)
Dim resultat As List(Of DroitsUtilisateurSession) = requeteTotale.ToList
Dim listeDroitsUtilisateur As List(Of DroitsUtilisateurSession) = New List(Of DroitsUtilisateurSession)
If (resultat IsNot Nothing) Then
For Each item In resultat
listeDroitsUtilisateur.Add(New DroitsUtilisateurSession With {.Role = item.Role, .ObjetLieu = item.ObjetLieu})
Next
End If
Return listeDroitsUtilisateur
End Function
EDIT 6: I found something about the limit size of the pile of w3wp applications. This can be linked to my problem...
Here is the link :
http://support.microsoft.com/kb/932909
I'm digging.
EDIT 7: So, I made a little change to my code. Now, when it have to calculate the rights, it let another thread do it. This thread has a bigger stack size. So I thought it can change something, but the same problem occurs...
And I don't said it before, but there is NO recursive code in my App.
Here is the code I implemented :
Dim ThreadD As ThreadDroits = New ThreadDroits
ThreadD.Username = User.Identity.Name
Dim t = New Thread(AddressOf ThreadD.ExecuteDroits, 419430400)
t.Start()
t.Join()
Dim listeDroits As List(Of DroitsUtilisateurSession) = ThreadD.ListeDroits
And here is the new class :
Public Class ThreadDroits
Private m_Username As String
Public Property Username As String
Get
Return m_Username
End Get
Set(ByVal value As String)
m_Username = value
End Set
End Property
Private m_listeDroits As List(Of DroitsUtilisateurSession)
Public Property ListeDroits As List(Of DroitsUtilisateurSession)
Get
Return m_listeDroits
End Get
Set(ByVal value As List(Of DroitsUtilisateurSession))
m_listeDroits = value
End Set
End Property
Public Sub ExecuteDroits()
ListeDroits = DroitsUtilisateurSession.getListeDroitsUtilisateurSession(Username)
End Sub
End Class

Creating new active directory account from an asp.net webpage

I'm 14 and I am really stuck. I wish to have an ASP.NET webpage that will enable users to create a new account in an organizational container. I have seen many pages on this but I just keep getting stuck.
Also, if this is possible, once the user has signed up would it be possible to run a script to enable the user for Office Communications Server 2007, or will I have to set the script as a cron job every 2 minutes?
Thanks in advance for your help.
Here is how I do it in a classic asp page:
Set objContainer = GetObject("LDAP://OU=OUtoPut,DC=YOUR,DC=ORG")
Set objUser = objContainer.Create("User", "CN=" & strCN)
objUser.sAMAccountName = strCN
objUser.givenName = strFName
objUser.sn = strLName
objUser.FullName = strCN
objUser.displayName = strCN
objUser.UserPrincipalName = strCN & "#your.org"
objUser.SetInfo
objUser.SetPassword strPass
objUser.pwdLastSet = 0
objUser.SetInfo
objUser.AccountDisabled = False
objUser.SetInfo
probably a little overdone toward the end with the setinfos, but it works.

Resources