Better way to Write this Classic ASP Code - unmanaged

This code works but when adding 1000 characters into it, the web page breaks and does not updated the record in SQL.
Set objRecordset3 = cn3.Execute("INSERT INTO MainDB SET Biography = '" & session("Biography") & "' WHERE ID = '" & session("ID") & "'")
Can anyone offer me a better way to write an UPDATE that will update at least 3,000 characters instead of 200 which this one can do?
Greatly appreciate your input.
Running Classic ASP on Windows 2008 sp2 and SQL 2005.

Related

Classic ASP language (monthname for chinese)

Have been struggling to find a solution for this.
I am looking for monthname to return the chinese version of January (or spanish etc.). At the moment it is returning english.
The site is installed on an english windows machine.
I have tried adding session.lcid as well as: <%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
but I keep getting the english version of the month name (and to change each occurrence is a major code change). Also I need to try and keep the date format as per what I have as changing that might be an issue as well.
Can anyone recommend an answer? Much appreciated.
You need the SetLocale function and the locale identifier of the language.
Sample test vbs script
Option Explicit
Dim language, outputString
For Each language In Array( "es-es", "en-us", "zh" )
SetLocale language
outputString = outputString & MonthName( 2 ) & vbCrLf
Next
WScript.Echo outputString
Output

VB6 object variable not set

I have a report in VB6 that has been completed. There is no issues whatsoever when I try to run it once, however, if I try to run it again I get the annoying "91 Object variable or With block variable not set". I don't see what I'm doing wrong, i get this error when I go to SELECT stuff from SQL SERVER...please see code below
g_SQL = "select Rpt as Label, rptOrder from tblData " & _
" where Rpt like '" & Client & "%' "
g_RS.Open g_SQL, g_cnDat, adOpenStatic
SO i do this here, a simple SELECT QUERY, and like I said it goes fine. I pull this data, use it for my report, then I do this
g_RS.close
When I try to run the report the 2nd time, it stops on
g_RS.open g_SQL,g_cnDat, adopenStatic
Why is this happening?
All set, it looks like i was opening it later on in the function and never closed it. Thanks for help!

Activating (bring to foreground) a specific window with vbscript

I'm not even sure where to start with my question, I tried a hundred things and googled for hours but didn't find anything useful. (I'm open to every dirty trick.)
Here's my problem:
I have a .hta-file with a listbox that looks like this:
It lists all sessions/modi of my SAP Gui running.
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
If application.Connections.Count > 0 Then
Set connection = application.Children(0)
If connection.Sessions.Count > 0 Then
Set session = connection.Children(0)
End If
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
Set optGroup = Document.createElement("OPTGROUP")
optGroup.label = "Server"
'count all connected servers
ConnectionCount = application.Connections.Count
If ConnectionCount > 0 Then
Sessionlist.appendChild(optGroup)
Else
optGroup.label = "No connection here."
End If
'count all sessions per server
If ConnectionCount > 0 Then
For Each conn in application.Connections
'Text output connections and sessions
SessionCount = conn.Sessions.Count
whatIsIt = conn.Description
ConnectionFeld.innerhtml = ConnectionFeld.innerhtml & " <br> " & SessionCount & " Sessions auf " & whatIsIt
'fill listbox with all connections
Set objOption = nothing
Set optGroup = Document.createElement("OPTGROUP")
optGroup.label = conn.Description
Sessionlist.appendChild(optGroup)
i = 0
'fill listbox with all sessions
For Each sess In conn.Sessions
i = i + 1
Set objOption = Document.createElement("OPTION")
objOption.Text = "Session " & i & ": " & sess.ID
objOption.Value = sess.ID
SessionList.options.add(objOption)
Next
Next
Else
Exit Sub
End If
My goal: When I doubleclick on one of the entries in that list, the selected instance of my SAP Gui should come to the foreground/get activated.
Unfortunately my taskmanager only lists one task and that is "SAP Logon". One of my opened windows also has the name "SAP Logon", all others have the same name: "SAP Easy Access".
The only way I can see the IDs of the connection (servername) and the IDs of the session is via extracting them with vbscript. (see above)
Is there any way to do that? The only workarounds I could think of after trying a thousand solutions are these two:
extremely ugly workaround:
If sessionID = sess.ID Then
Set objShell = CreateObject("shell.application")
objShell.MinimizeAll
sess.findById("wnd[0]").maximize
End If
It minimizes all windows an then maximizes the selected SAP window. Unfortunately My HTA-GUI also gets minimized which kinda sucks.
Second idea:
Somehow get to these clickable thingies by shortcut and put that in my script or some other ugly way.
By hand you have to do this:
Click on that little arrow, rightclick on the icon and then leftclick on the name.
Is there any way to automate this? It's driving me crazy.
Hope someone can help me, it would be GREATLY appreciated.
PS: I'm sitting on a machine with restricted rights and so I may not be able to tackle this with Windows API-ish solutions.
EDIT concerning comments:
It is not possible:
to change registry entries
create COM objects
work with anything else than VBScript
Similarly, it also works with the following commands:
session.findById("wnd[0]").iconify
session.findById("wnd[0]").maximize
I found it...
The resizeWorkingPane method - for changing the size of a window - also works on windows in the background. If you change the parameters, the window will come to the foreground.
session.findById("wnd[0]").resizeWorkingPane 300,200,false
I have to partially revoke this, because it doesnt work on all windows. I'm still not sure why, but it keeps failing sometimes. Still, it seems to me, that this is the closest you can get.
From Help.
Activates an application window.
object.AppActivate title
object
WshShell object.
title
Specifies which application to activate. This can be a string containing the title of the application (as it appears in the title bar) or the application's Process ID.
I don't know what access to info you have about the window. Some COM objects have a HWnd property. This post gets you how to convert a hwnd to a ProcessID to be used above.
How to find the window Title of Active(foreground) window using Window Script Host
This shows how to convert a process command-line to a ProcessID. To see what properties and methods are available use the command-line tool wmic (wmic process get /? and wmic process call /?)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
For Each objItem in colItems
msgbox objItem.ProcessID & " " & objItem.CommandLine
Next
This is a 100% of the time solution. It's ugly but it works. You can swap out the IQS3 t code for any other one you can confirm the user won't be in and will have access to. Also part of my reasoning for selection of this code is it loads fast.
Set objShell = CreateObject("wscript.shell")
session.findById("wnd[0]/tbar[0]/okcd").text = "/nIQS3"
session.findById("wnd[0]").sendVKey 0
objShell.AppActivate(cstr(session.ActiveWindow.Text))
session.findById("wnd[0]/tbar[0]/btn[3]").press

Response.Write("OK") gives error Object required: "" in VBScript

What should I do to use Response.Write in VBScript?
Everything else works fine up to this statement.
I never used VBScript before...
The code, which is my first in VBScript and is being written incrementally, works OK with exception of these objects:
WScript.Echo Response.Write Print
I have enabled ASP but I couldn't find a way to install these objects on my PC, which acts as a development server. The production website uses VBScript, ASP and SQL Server. Here is the code:
'...
Do While Not Rs.EOF
AllTerms = AllTerms & Rs("Term")
Rs.MoveNext
Loop
MsgBox AllTerms
' # Print AllTerms
' WScript.Echo AllTerms
' Response.Write Rs("Term")
Rs.Close
Are you using ASP? Response is part of the ASP object model. It's not available when running a VBScript under the Windows Script Host.
Edit:
I see you've updated your code and it looks like you are indeed using ASP. Since you're collecting all of the recordset info in a variable named AllTerms, you should be able to display it using the line:
Response.Write AllTerms ' Use this in place of: MsgBox AllTerms
But if you're new to ASP, you may want to just create a simple page just to test your configuration. Something like this should do:
<%
Response.Write "Today is " & Date
%>
Save it with an .asp extension, request the page from the web server, and make sure the output is proper.

Error 91 using CreateObject on XP machines

I have an old VB6 app that I've distributed to several users running XP, Windows 7 and Windows 8. The following code is throwing an Error 91 ""Object variable or With block variable not set".
Const ssfPERSONAL = 46 'set directory to the common Documents folder
Dim strMyDocsPath As String 'stores common docsPath
On Error GoTo ErrorHandler
strMyDocsPath = CreateObject("Shell.Application").NameSpace(ssfPERSONAL).Self.Path
Specifically, the last line is the issue. I want strMyDocsPath to point to the common documents folder on the user machine. It works fine in Windows 7 and 8, but not on XP machines except the XP development machine where it runs without a hitch.
On the problem computers, I have tried re-registering scrrrun.dll and got a message it registered successfully. I tried downloading and installing the VB6 distributable SP6 files and still get the error. I have searched several forums and just can't figure it out. Any ideas?
It is usually useful to un-lump complex one-liners in one call per line fashion when debugging such kind of an error:
Dim DebugObj1 As Object
Dim DebugObj2 As Object
Dim DebugObj3 As Object
Set DebugObj1 = CreateObject("Shell.Application")
Debug.Print "1: " & CStr(DebugObj1 Is Nothing)
Set DebugObj2 = DebugObj1.NameSpace(ssfPERSONAL)
Debug.Print "2: " & CStr(DebugObj2 Is Nothing)
Set DebugObj3 = DebugObj2.Self
Debug.Print "3: " & CStr(DebugObj3 Is Nothing)
strMyDocsPath = DebugObj3.Path
Debug.Print strMyDocsPath
After that it is easier to spot what call doesn't return useful object, exactly. In your case it is most likely .NameSpace(ssfPERSONAL).
I was able to reproduce your problem in Windows XP SP3 if Shared Documents are disabled. There are many ways to disable them. See this, for example: http://www.howtogeek.com/howto/windows/how-to-remove-shared-documents-icon-from-my-computer-in-windows-xp/
As a side note, ShellSpecialFolderConstants.ssfPersonal is actually 0x05, see MSDN. The value 46 (or 0x2e) you use is CSIDL_COMMON_DOCUMENTS which indeed translates to Common Documents folder like C:\Documents and Settings\All Users\Documents. Probably, it is not the very best practice to use misleading naming.

Resources