Infinite classic Asp do while loop - asp-classic

I have this same type of loop running on several pages, but the one that I said I'd get done in 1 day just... Ignores the out.movenext and prints only the first result out of a possible 10 results until it crashes. The SQL is fine. I got it with a tracer.
Changes:
I originally had the movenext last before the loop - but moved it up one line for tracing. Tried (out = out.movenext , out = out.next) to see if it would do anything. And I tried putting an integer count in to have it stop after 20 loops so I can debug it faster. The int changes, the data prints, but out doesn't advance.
strSQL = "SELECT [RecordID],[SubmitDate],[DataEntered] FROM [ManagerFileReview] where submitdate = '" & timetap & "'"
out = cnt.execute(strSQL)
out.movefirst
response.write "<table>"
Do while not out.eof
response.write "<tr><td>"
response.write "<table><thead></thead>"
response.write "<tr><td>Submit Date:</td><td>" & out(1) & "</td></tr>"
response.write "<tr><td>Data Entered:</td><td>" & out(2) & "rrrrrrrrrrr</td></tr>"
out.movenext
response.write "passed movenext</table></td></tr>"
loop
response.write "</table>"
Edit: Forgot the "SET" before the cnt.execute

The logic looks OK, unless I'm missing something. Even though out isn't listed as a reserved word with MS, I do wonder if it's the problem.

Found it.
Didn't have SET before the out = cnt.execute(strSQL)
Should have been
set out = cnt.execute(strSQL)

Related

How to get package name (Source Name) from the event log for SSIS errors in ASP.NET

I’m successfully reading the server event log to display SSIS errors from the Application event log. The aim is to make it possible to do first line troubleshooting without having to log into the server as an Administrator.
I’m using the EventLogEntry in vb.net to show Errors where the source is SQLISPackage110. However what’s stumping me is that when viewing the errors in the event log there is a “Source Name” property that displays the package name. However the EventLogEntry doesn’t seem to have this property which makes it impossible to tell which package has returned the error.
Has anyone come across this and managed to find a way round it?
A screenshot of the error and some of my vb.net code is below
Dim myEventLogEntryCollection As EventLogEntryCollection = myEventLog1.Entries
myEventLog1.Close()
Dim x As Integer
Dim entry As EventLogEntry
If myEventLogEntryCollection.Count > 0 Then
strTable += "<table class='table table-bordered'><tr><th>Time Written</th><th>Source</th><th>Event type</th><th>Message</th></tr>"
For Each entry In myEventLogEntryCollection.Cast(Of EventLogEntry).Reverse 'cast and reverse to show newest first
If entry.Source = strEventSource And (entry.EntryType.ToString = "Error" Or entry.EntryType.ToString = "Warning") Then
strTable += "<tr>"
strTable += "<td>" + entry.TimeWritten.ToShortDateString + " " + entry.TimeWritten.ToShortTimeString + "</td>"
strTable += "<td>" + entry.Source.ToString + "</td>"
strTable += "<td>" + entry.EntryType.ToString + "</td>"
strTable += "<td>" + entry.Message + "</td>"
strTable += "</tr>"
x += 1
End If
If x > 100 Then Exit For 'could be 1000s in the log
Next
strTable += "</table>"
End If
As you've noticed, "Source" is NOT one of the LogEntry properties.
Instead the word "Source" is just text trapped inside of the larger Message property. So, to get the "Source" information you're going to have to parse it out of the Message. Split the message into lines. Then loop over the lines and do something when you find a line containing the word "Source"
This code is NOT tested. But, just to give the idea..
Dim messageLines As String() = Nothing
messageLines = entry.Message.Split(Environment.NewLine)
Dim line As String
For Each line In messageLines
If line.Contains("Source") Then
'your code here
Next line
SSIS packages can log to many destinations. And yes, logging to the Windows Event log is an option, but I've seldom seen it used in practice. Windows Event Logs aren't permanent. By default, they are going to start trimming the history once they get over twenty megabytes in size. They are a bad place to store SSIS log information for troubleshooting.
Would you consider gently suggesting to your package authors that they use SSIS SQL logging instead? If they logged to SQL then you'd have the information you need arranged, and stored in a nice searchable manner that would allow for easier querying, aggregation, and analysis across your entire organization. You'd even have the source column you could use to get the exact info you need.

Classic ASP Error: Operation is not allowed when the object is closed

I have cruised and implemented code from some of the other responses to this question, but I'm still having no luck. I am still getting the error.
If ((bReport And bIsDate And CheckPermissions("lotsales")) Or Request.QueryString("report")) Then
OpenDB
Dim oRs, sSQL, sSQL2, iCancellations, iSales, sDate, sInitDate, sEndDate, iPhaseID, iPhaseNumber, rowCount
sInitDate = Request("startDate")
sEndDate = Request("endDate")
sSQL = "sp_get_lot_sales_test '" & sInitDate & "', '" & sEndDate & "', " & sPhase & ", '" & sReportView & "'"
'response.write vbNewLine & "<!-- sql: " & sSQL & "-->" & vbNewLine
'response.write sSQL
'response.Flush
Set oRs = ExecuteCommand(sSQL,1)
End If
And then here is where the error occurs -
If (oRs.EOF) Then <-- fails here
Response.Write("<TR><TD ALIGN=""center"">There is no data to report on!</TD></TR>")
Else
Do While Not oRs.EOF
As a last resort I am going to go back to the stored procedure and deconstruct it to make sure all is well there. Does anyone have any insight as to why I might be getting the error? I am not issuing a close anywhere.
Here is the ExecuteCommand function -
Function ExecuteCommand(s,i)
On Error Resume Next
Set ExecuteCommand = oDBc.Execute(s, , i)
End Function
This may be old, but I frequently come across that error (operation is not allowed when object is closed).
What I do is in the stored procedure, I add the follwing:
SET NOCOUNT ON
SET ANSI_WARNINGS OFF
right below the AS in the procedure.
That's all I do and the problem goes away.
I am maintaining some old Classic ASP code for a client, code that we took over from a prior developer, and this bug drove me crazy for 4 hours.
I finally discovered a few PRINT statements in the associated SQL stored procedure, which were there for troubleshooting or checking values but don't actually return rows, yet they caused this to fail:
Set cnContentDB = Server.CreateObject("ADODB.Connection")
cnContentDB2.Open sString
sSQL = "EXEC YourStoredProc"
Set oRS2 = Server.CreateObject("ADODB.Recordset")
oRS2.Open sSQL, cnContentDB
if not oR2.EOF then 'THIS WAS GIVING THE ERROR,
'EVEN THOUGH THE STORED PROC ALWAYS RETURNS RECORDS
I removed the Print statements, and the error went away.
Although this is years old, we still end up here looking for solutions.
The cause of this error for me was that the User did not have Execute permission on the Stored Procedure. Granting Execute permission resolved the error.
You need a connection object.
set conn = server.CreateObject("adodb.connection")
set oRs = conn.execute(sSql)

Reading CSV in Recordset?

Let me start off by saying that I am very greatful to have a place to go to when I need help with some code and I'm even more thankful when I see people trying to help out, so for everyone here Thank you for looking at my question/problem even if you don't have an answer.
With that said, on with my question/problem:
I have been trying to get this to work but I cannot seem to find the syntax error!! :-(
Can anyone please help me...
Here is the code:
dim strPathtoCSVFolder,strPathtoCSVFile,strPathtoCSVFileTWO
strPathtoCSVFolder="D:\classic_asp\test\" & Request.QueryString("XTNO") & "\Data\"
strPathtoCSVFile="Unit_" & Request.QueryString("XTNO") & "_Year_" & Request.QueryString("year") & "_Q_" & Request.QueryString("q") & "_MERGE_DataCsv.csv"
strPathtoCSVFileTWO="Unit_" & Request.QueryString("XTNO") & "_Year_" & Request.QueryString("year") & "_Q_" & Request.QueryString("q") & "_MERGE_DataCsv_SORTED.csv"
Set Conn = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathtoCSVFolder & ";Extended Properties=""text;HDR=YES;FMT=Delimited"""
dim strDirInfoX
strDirInfoX="SELECT STATE, SUM(GALLONS) as Total FROM " & strPathtoCSVFile & " GROUP BY STATE "
'''''' response.write strDirInfoX
dim strTxttoMem
dim strsource
strsource="RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001"
RS.Open strsource
'response.write strsource
redim FieldNames(rs.fields.count)
redim FieldTypes(rs.fields.count)
For i = 0 To (rs.Fields.Count - 1)
FieldNames(i) = cstr(trim(rs.Fields.Item(i).Name))
FieldTypes(i) = cstr(trim(rs.Fields.Item(i).Type))
Next
RS.Close
RS.Open strDirInfoX, Conn, 3, 3, &H0001
Do Until RS.EOF
'''' for i=0 to ubound(FieldNames)-1
''' response.write(FieldNames(i) & " = " & RS.Fields.Item(FieldNames(i)) & "<br>")
strTxttoMem=strTxttoMem & RS("STATE") & RS("total")
'' next
RS.MoveNext
Loop
RS.Close
Conn.Close
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile(strPathtoCSVFolder & strPathtoCSVFileTWO)
tfile.WriteLine(strTxttoMem)
tfile.close
set tfile=nothing
set fs=nothing
Thank you so much for any help...
Well, without running your code, I spotted an error in this part:
dim strsource
strsource="RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001"
RS.Open strsource
or to shorten it, you are doing this:
RS.Open "RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001"
change it to RS.Open strDirInfoX, Conn, 1, 3, &H0001 and that part will run better.
This is almost impossible to answer, there could be multiple errors and much depends on what is declared before, eg an option explicit makes a huge difference (and is advisable).
Since debugging in the browser is difficult at best, you copy this code - that comes from an asp file i guess - and put it in a vbs script, replace the response.write with wscript.echo and run the code.
Then you get an error at some line, correct it and so on, afterward replace the echos's by response.write's and you'r done.
I also recommend useing Firefox and the Firebug plugin to do your testing, you will get more debugging info there, at least use the developer view in Chrome or IE
Success..
Been some time working on VBScript but shouldnt tfile.close be tfile.Close?
Did you try reading the file as a text file rather than connecting to it with an ADODB connection? Since it is a CSV file, you might be able to read it as a plain text file. You can split the content with comma and loop and get what you want.
If you want to access it using ADODB connection, try saving the file with an xlsx extention(Either copy the contents through code or save it manually. The same code might work).
Shamelessly adding a link to my blog on ADO
http://www.blogger.com/blogger.g?blogID=3033014869583885023#editor/target=post;postID=8274119342550879092

How to properly report / handle classic asp page errors and database errors

I have been trying to create an error handling path for our classic asp website. I have been searching for information for 3hrs now and have not found much even here on stack overflow. So if you can point me towards a duplicate great ... I couldn't find anything although it must exist.
My plan is the following ...
Have proper error handling in the stored procedures. Any errors that occur get inserted into an error table and are also raised back up to the application.
Have "On error resume next" set on the page. Then check the connection.errors collection for errors. As well as Server.GetLastError() property.
If there are any redirect to a page to to display safe error information and insert another record into another database table to tie the page name where the error occurred to the already existing database error in the database table mentioned above for later debugging purposes.
I have created the following page to to begin testing this out. However it is not working.
Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandType = adCmdStoredProc
on error resume next
cmd.CommandText = "spReturnDBException"
cmd.CommandTimeout = 30 ' 2 minutes
cmd.Execute
dim objErr
set objErr = Server.GetLastError()
if objError.ASPCode <> 0 then
response.write("ASPCode=" & objErr.ASPCode)
response.write("")
response.write("ASPDescription=" & objErr.ASPDescription)
response.write("")
response.write("Category=" & objErr.Category)
response.write("")
response.write("Column=" & objErr.Column)
response.write("")
response.write("Description=" & objErr.Description)
response.write("")
response.write("File=" & objErr.File)
response.write("")
response.write("Line=" & objErr.Line)
response.write("")
response.write("Number=" & objErr.Number)
response.write("")
response.write("Source=" & objErr.Source)
else
response.write("There's nothing wrong.")
end if
Dim objErr2
for each objErr2 in objConn.Errors
response.write("<p>")
response.write("Description: ")
response.write(objErr2.Description & "<br />")
response.write("Help context: ")
response.write(objErr2.HelpContext & "<br />")
response.write("Help file: ")
response.write(objErr2.HelpFile & "<br />")
response.write("Native error: ")
response.write(objErr2.NativeError & "<br />")
response.write("Error number: ")
response.write(objErr2.Number & "<br />")
response.write("Error source: ")
response.write(objErr2.Source & "<br />")
response.write("SQL state: ")
response.write(objErr2.SQLState & "<br />")
response.write("</p>")
next
Free(cmd)
Free(con)
In the stored procedure I simply RAISERROR( N'Lets throw an error because I want to!', 17, 0 );
The output I get every time is as follows ...
ASPCode=ASPDescription=Category=Column=-1Description=File=Line=0Number=0Source=
Description: Help context: Help file: Native error: Error number: Error source: SQL state:
Why am I not getting any error information on the conn.Errors loop?
Resolved.
I was using a different connection object for the loop that loops through the connection.Errors ... copy paste error.
However on a side note ... I found it extremely difficult to find information on how to even do what I've so far.
here's some additional resources:
some general topics:
http://social.msdn.microsoft.com/search/en-US?query=Server.GetLastError%28%29&refinement=89
a specific example:
http://support.microsoft.com/kb/224070

Classic ASP: Execute 2 Update Statements in single function

I am writing Classic ASP program.In one function, I have to use 2 update statements to one table in one function. First Statement is update the quantity of invoice and second update statement is base on that update Purchase Order quantity and Purchase Requisition quantity, I need to update one flag field. Can I write in same function as following:
SET RS = app.Execute("SELECT PRInvoiceNo, Quantity FROM PurchaseOrderDetails WHERE CoID='" & param & "'")
do while RS.EOF=false
app.Execute("UPDATE PurchaseRequisitionDetails SET PO_Quantity = PO_Quantity + " & RS("Quantity") & " WHERE CoID='" & param & "' AND PRInvoiceNo = '" & RS("PRInvoiceNo") & "'")
app.Execute("UPDATE PurchaseRequisitionDetails SET FullyPaidFlag=CASE WHEN PO_Quantity >= Quantity THEN 1 ELSE 0 END WHERE CoID='" & param & "' AND PRInvoiceNo = '" & RS("PRInvoiceNo") & "'")
RS.MoveNext
loop
The problem is in the loop the first statement is properly worked. Second one not work. What can it be? Can I do like this or not?
Well, I have to go, but be sure to check the following:
Response.Write(RS.RecordCount) -- are there any records? Or, do a Response.Write("hello") inside the loop to make sure.
Check that RS("Quantity"), param, etc are not null. If they are, your string concatenation will result in a null string.
Also, please, please don't forget to escape your variables!
Replace(param, "'", "''")
Good night!

Resources