Classic ASP - Server.CreateObject - Unauthorized operation - error-handling

I have the following code :
Set objUpload = Server.CreateObject("ASPUploadComponent.cUpload")
It seems to be failing, because the following debug code :
Response.Write(" begin ")
Response.Write(" Err : " & Err & " ")
Response.Write(" TypeName(Err) : " & TypeName(Err) & " ")
Response.Write(" Str(Err.Number): " & Err.Number & " ")
Response.Write(" Str(Err.Source): " & Err.Source & " ")
Response.Write(" Str(Err.Description): " & Err.Description & " ")
Response.Write(" TypeName(objUpload) : " & TypeName(objUpload) & " ")
Response.Write(" end ")
Outputs :
begin Err : -2147352567 TypeName(Err) : Object Str(Err.Number): -2147352567 Str(Err.Source): ASPUploadComponent Str(Err.Description): Unhandled error: 007~ASP 0104~Op�ration non autoris�e~ TypeName(objUpload) : Empty end
It says unauthorized operation.
This exact same way of creating the object works perfectly on some other script, but not here.
What could possibly cause this?
Edit
It's different from this question, because you would have to know it's related to the file size to begin with, so while the solution is the same, the other question would have not helped me, because I wouldn't have searched for it in the first place.

So after more digging, I found the actual reason, and it's definately not straight forward.
It is due to the fact that the file I was trying to upload, despite being rather small (1.27 Mb) was exceeding the miaximum size allow by IIS. And, for some reason which I can't explain, instead of letting me know that this was the issue, the COM object would just refuse to be created.
To solve this, one must change the maximum allowed size in the IIS settings as follows :
1):
:
It's in french, but you'll figure out.

Related

Is value of vbNewLine platform-dependent?

Is vbNewLine constant equivalent to vbCrLf (0x0D 0x0A) or is it equivalent to Environment.NewLine which is platform-dependent?
vbNewLine definition is not clear enough here: Represents a newline character for print and display functions.
In Windows, vbNewLine has 2 characters. It would be best if someone could verify vbNewLine at Mono. :)
I would prefer vbNewLine before Environment.Newline if they were equivalent because it is handier.
For Mono, you can find the Microsoft.VisualBasic.Constants source code here. It explicitly states that vbNewLine is equal to vbCrLf:
Public Const vbNewLine As String = vbCrLf
For completeness, the corresponding .NET source code can be found here.

Download File and Extract Immediately - File is being used by another process

I'm looping through a list of zip files and downloading them from a WebClient. I'm trying to extract them immediately after they download, but getting an error that the file is being used by another process.
Error: The process cannot access the file 'c:\temp\test.zip' because it is being used by another process.
The only thing that I can think of is that maybe the file is still "in use" for a short time after being downloaded? DownloadFile does block ("This method blocks while downloading the resource." - http://msdn.microsoft.com/en-us/library/ez801hhe(v=vs.110).aspx), so I can't see it being an issue with the file still downloading.
Any ideas on a workaround?
Using client As New WebClient
oLog.Info("Downloading " & strFileServer & " to " & strFileLocal & "...")
If Not Directory.Exists(strPathLocal) Then Directory.CreateDirectory(strPathLocal)
client.DownloadFile(strFileServer, strFileLocal)
End Using
Using archive As ZipArchive = ZipFile.OpenRead(strFileLocal)
For Each entry As ZipArchiveEntry In archive.Entries
oLog.Info("Extracting " & entry.FullName & " to " & strPathLocal & "...")
entry.ExtractToFile(strFileLocal, True)
Next
End Using

Out of Memory Error VB6 when try to add an existing Class module

I'm working on a project in VB6. I have to add a download functionality. It contains 1 form, 1 class module and 1 module (bas) files. When I add the existing module to my project, it is successful But when I try to add the class module or the frm file to the project, it says OUT OF MEMORY. I have been banging my head against this issue for quite some time now but couldn't find any solution.
I cannot post any code because it's a company project. All I can tell is that its a huge project with thousands of lines of code. The module I'm trying to add is used to download a file over HTTP, and it accesses the methods in Wininet.dll.
I don't know if the project has reached it maximum limit of lines of code, or whether it's an issue of variables.
I have heard that making a DLL can solve this issue, but we don't need that. Can anyone help?
I think I've faced something similar in the past, and after some digging and trying different things it turned out to be the number of variables / forms / controls that we had in the project. There is a limit to the number of unique variable, constant, and control names you can have in the project.
The way we proved it was to add the module that didn't quite break it, then add an empty module. In the empty module start adding variables until it breaks, it shouldn't take to long.
We cured it by going through the code and changing names of labels on forms to be control arrays, using constants for strings, and removing any code that was old an no longer required. Try to remove unused variables as well.
If it makes life easier you could try moving some of the code out to dll's.
Hope this helps.
Cast your eye over this, the sub sections might help:
VB6 Project Limitations
You know there are high level objects available that do in two or three lines what requires many in Wininet.
Try this way using xmlhttp. Edit the url's etc. If it seems to work comment out the if / end if to dump info even if seeming to work. It's vbscript but vbscript works in vb6.
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "http://www.microsoft.com/en-au/default.aspx", False
'This is IE 8 headers
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
line =""
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error getting file"
Line = Line & vbcrlf & "=================="
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Line = Line & vbcrlf & "Source " & err.source
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
Line = Line & vbcrlf & File.getAllResponseHeaders
wscript.echo Line
Err.clear
wscript.quit
End If
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile "c:\users\test.txt", 2

Error 440 in Visual Basic Application

There is an old VB application running at one of my clients.
An exception is throws in this peice of code:
cn=GetIndexDatabaseConnectionString()
sSql="SELECT * FROM Arh_Naroc WHERE StNarocila = '" & isci & "'"
rs=CreateObject("ADODB.Recordset")
Call rs.Open(sSql,cn)
The exception happens in rs.Open() function. "Error number 440 occured."
This are SBL scripts for KOFAX engine and it's many years old.
The whole SW was transferred from old XP computer to Windows 7 and looks like there are problems everywhere.
Can some one help me determine what is the problem here. At least if I could get a proper error message back in msgbox would be most helpful.
EDIT:
This is the connection string function.
Function GetIndexDatabaseConnectionString
Dim objXmlDocument As Object
Dim objXmlGlobalSettingsFileParh As Object
Dim objXmlIndexDatabaseConnectionString As Object
Dim strGlobalSettingsFilePath As String
Dim strTemp As String
Const strSettingsFilePath = "C:\Data\LocalDocsDistibutingSystem\Settings.xml"
Set objXmlDocument = CreateObject("MSXML2.DOMDocument")
objXmlDocument.Load strSettingsFilePath
Set objXmlGlobalSettingsFileParh = objXmlDocument.selectSingleNode("DocsDistributingSystem/GlobalSettingsFilePath")
strGlobalSettingsFilePath = objXmlGlobalSettingsFileParh.childNodes(0).Text
Set objXmlGlobalSettingsFileParh = Nothing
Set objXmlDocument = Nothing
Set objXmlDocument = CreateObject("MSXML2.DOMDocument")
objXmlDocument.Load strGlobalSettingsFilePath
Set objXmlIndexDatabaseConnectionString = objXmlDocument.selectSingleNode("DocsDistibutingSystem/AscentCapture/IndexDatabase/ConnectionString")
strTemp = objXmlIndexDatabaseConnectionString.childNodes(0).Text
Set objXmlIndexDatabaseConnectionString = Nothing
Set objXmlDocument = Nothing
GetIndexDatabaseConnectionString = strTemp
End Function
This is the relevant line from Settings.xml:
<ConnectionString> Provider=OraOLEDB.Oracle;Data Source=LINO2;User Id=****;Password=****;OLEDB.NET=True; </ConnectionString>
The real data is masked with *. The connection to Oracle appears to be ok. I created ODBC and linked server to sql using the provider and connection data. It works. It must be something missing installed on the computer for ADODB to work...
The connection appears to be working OK. There is no error when its initialized.
The error happens in Call rs.Open(sSql, cn). All i want is the detailed error message when the error happens...
Many thanks.
As it states on MS Knowledge Base
An error occurred while executing a method or getting or setting a
property of an object variable. The error was reported by the
application that created the object. Check the properties of the Err
object to determine the source and nature of the error. Also try using
the On Error Resume Next statement immediately before the accessing
statement, and then check for errors immediately following the
accessing statement.
So as they suggest check the Err object, in a similar fashion to:
If Err.Number <> 0 Then
Msg = "Error: " & Str(Err.Number) & ", generated by " _
& Err.Source & ControlChars.CrLf & Err.Description
MsgBox(Msg, MsgBoxStyle.Information, "Error")
End If
So this will bring back the error in a MsgBox, however you can just use Response.Write if you want it easier to copy & paste etc..
to get the error description you can do as follows :
Function GetIndexDatabaseConnectionString()
On Error GoTo Errorfound
'your
'function
'body
Exit Function
Errorfound:
With Err
MsgBox "Source: " & .Source & vbCrLf & "Desc: " & .Description, vbCritical, "Error " & CStr(.Number)
End With 'Err
End Function

Debug a bad DLL calling convention

How do I debug a bad DLL calling convention error in MSAccess VBA code?
I made some changes to a function in a module and then got the error. How do a debug it to find the cause?
The error occurs on the Exit function statement of the function.
I fixed this problem by making a change in one of my class modules, executing a compilation from the Debug menu, and then undoing the change.
Background: In my case I've seen this in Excel without any external references. It happened, as with your problem, on an Exit Function call. Excel doesn't seem to have a /decompile option. I suspect that one of my class modules had mis-compiled for some reason, and Excel won't re-compile unless it thinks something has changed.
Have you checked your references and decompiled?
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE"
"d:\My Documents\access\mayapp.mdb" /decompile
See also: http://www.granite.ab.ca/access/decompile.htm
VBScript Decompile
Check references in code
Dim ref As Reference
Dim sMsg As String
''Available since 2010
If BrokenReference Then
For Each ref In References
''Available since at least 2000
If ref.IsBroken Then
sMsg = sMsg & "Ref Name: " & ref.Name
'Also, if required
'sMsg = sMsg & vbCrLf & "Built In: " & ref.BuiltIn
'sMsg = sMsg & vbCrLf & "Full Path: " & ref.FullPath
'sMsg = sMsg & vbCrLf & "GUID: " & ref.Guid
'sMsg = sMsg & vbCrLf & "Kind: " & ref.Kind
'sMsg = sMsg & vbCrLf & "Major (version number): " & ref.Major
'sMsg = sMsg & vbCrLf & "Minor (version number): " & ref.Minor
sMsg = sMsg & vbCrLf & "=================================" & vbCrLf
End If
Next
MsgBox sMsg
End If
I experienced and worked around this error using the .NET library for WinSCP from MS Access VBA.
What happened was:
A function UploadSomething for connecting to an SFTP server and uploading a file worked fine.
Within the function UploadSomething changed the "resume support" option with this code: myTransferOptions.ResumeSupport.State = TransferResumeSupportState.TransferResumeSupportState_Off
After the change, the code worked as desired. However in the code that called UploadSomething, Error 49 was thrown after the function had finished.
The error happened both when stepping through the code using the debugger and when executing at once outside of the debugger. Recompiling the project didn't work for me.
What did work was this:
Remove the reference to the COM component
Add the reference to the COM component
Recompile
In Excel VBA, this can be caused by any of several problems:
A parameter or return-value type mismatch.
An object method (such as AutoFit) applied to an erroneous object
variation for which that method isn’t available.
A call to an external library function.
Broken library references
For resolutions to these causes, see my post at: Runtime Error 49, Bad DLL calling convention
I've just got this in Excel and wondered if anyone else have gotten it previously. My solution was to move around the references to my own DLL and click 'Compile <Project>'.
We've run into some problems with VBA when trying to call a DLL compiled in Intel Fortran. It turns out that you need to align the calling conventions back to a "C" context with the compiler flag calling convention: cfv
More info here on the Intel website
Another useful thread on the same problem: Intel Fortran DLL <-> C