In asp, how to set boolean values to english? - iis-7

When I run this:
<%
www = false
response.write www
response.write "UPDATE table SET domain='"&www&"' WHERE id=n"
%>
I get this:
false
UPDATE table SET domain='Falso' WHERE id=n
Notice the 'Falso' word that is in Portuguese instead of English.
Is it possible to change the boolean values to English?
I have a Windows 2008 / IIS 7 in pt-BR.

This question was asked just recently here
I don't have a good machine to test the following code, which came from a working solution. It forces the locality you need (of course you can change the locality to what you need it to be, if 1033 is not your goal)
<%
Response.Write FormatDateTime(Now) & "<br />"
oldLocale = SetLocale(1033) '1033=English(US)
Response.Write FormatDateTime(Now) & "<br />"
SetLocale oldLocale
Response.Write FormatDateTime(Now) & "<br />"
%>

I'll not be able to provide any more testing for this 'issue' anymore.
That's because I've made a decision to format my windows and install a new one now in english.. I did this because I'm running out of time, I need to put this server working as soon as possible..
But I want to thank everyone who contributed on finding the resolution for this problem =)
If anyone is having the same issue, please leave your comment, so the others can provide more options to try to solve this.

If you dont mind changing the code, you could use a function to print the boolean value. For me thats not an option, but i'm starting to believe its the only way.
Function PB(pVal)
If pVal Then
PB = "true"
Else
PB = "false"
End If
End Function
Response.Write "UPDATE table SET domain='"&PD(www)&"' WHERE id=n"

Just use string instead:
www = "false"
Then it won't be affected by regional settings.
If you want to keep working with actual boolean values, use Parameters instead of raw SQL.

Related

Handling Chinese in ASP classic

I write the following piece of codes :
rst.Open(strSQL & Request.QueryString("C-PLACE")), conn, 0, 1
But got the following error. However, if the querystring is in English or just number, no error will pop out. Any guru can help please ?
Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
/deliverable/GetMemberTest.asp, line 19
It's going to either be passing an encoding variable to the server, or in the case of your error, its saying "too few parameters". In this case, the parameter is "C-PLACE" and its suppose to be passed to your asp script from the previous page's link, something like:
/deliverable/GetMemberTest.asp?C-PLACE=THECPLACE
https://www.w3schools.com/asp/coll_querystring.asp
(citation about query strings)
or something like that .. obviously its not actually "THECPLACE", but just saying a QueryString("VARIABLENAME") looks to the URL of the previous page to pass the parameter to the script, so that error message should of done something to add a ? mark = C-PLACE= to something, and we aren't seeing that. So something on the previous page that was suppose to add this when they click a submit button didn't do it's job, or the script is just getting run on its own without the proper previous page's work being done to prepare it to execute properly on the following page.
It will also be of note that these types of things are easily hacked through sql script injection, so if you aren't validating your url first, someone could use some code to escape out of your sql and add their own code, such as one to drop your tables ..., so make sure you validate the variable FIRST instead of dumping it straight into your code. I can give some guidance into that later, but first lets figure out your problem.
(side note - can i request strSQL from you? Can you put this line in before that line:
<%
response.write("strSQL is " & StrSQL & "<BR>")
%>
All this code does is display what is stored in the StrSQL variable, see if we can figure out what is going on here. Also take note that your error message indicated that it expected 2 parameters, so we are missing 2 for this script to run properly.
EDIT - try this encoding:
<%
Response.CodePage=65001
Response.Charset="UTF-8"
Response.ContentType = "text/html"
%>
Try this strSQL, you didn't need the Response.Write and on C-PLACE you want to use '' instead of "" because the "" will exit you out of the SQL statement. Try this, and let me know how it works, but I still think we are going to need another parameter supplied to it, unless its getting one from the string and then it isn't actually counting the one supplied from the url perhaps.
<%
strSQL="SELECT * FROM DetailMemberInfo
WHERE C-PLACE=" & strSQL & Request.QueryString('C-PLACE'))"
%>

Asp pattern page execution

I am working on an old asp project. I am new in project. My question is,
I required to execute the certain number of pages in a specific time but when I put in a loop to execute the page for certain pattern it execute only one pattern and shows time out expired problem. Though I searched in net what ever answer I get it will not fulfill my requirement. So my team lead said we have to find out some thing that can execute my page for 3 min each then it call back freshly. Is there any method is there in asp. as I am new in asp. as it possible or share some idea.
I want to execute for each pattern. Here is my simple code.
dim arrList()
dim mySQL,x,strPtrn
mySQL=""
x=0
strPtrn=""
mySQL="select distinct(pattern_no) from pattern_master where std between (dateadd(hh,8,getdate())) and (dateadd(hh,11,getdate()))"
set rstptrnmst= conn.Execute(mySQL)
do until rstptrnmst.EOF
for each ptrn in rstptrnmst.Fields
' Response.Write(x.name)
'Response.Write(" = ")
'Response.Write(x.value & "<br />")
ReDim Preserve arrList(x)
arrList(x)=ptrn.value
x=x+1
next
Response.Write("<br />")
rstptrnmst.MoveNext
loop
rstptrnmst.close
conn.close
'for each ptrn in arrList
'response.Write("<br>" & ptrn)
'next
for each ptrn in arrList
Session("pattern")=ptrn
server.Execute("processFNO.asp")
Session("pattern")=""
response.write("The first pattern " & ptrn & "<br />")
next
'Response.Redirect("processFNO.asp?fno="&arrList(0))
%>
So I want execute that page for each pattern. How can I? For each pattern it take 3 min(approx).any idea?
thanks for advance.
If your script is going to take that long to run you will need to set the script timeout option to cater for that:
<%
Server.ScriptTimeout = 180
%>
The timeout is set in seconds, with the default being 90. You should set this at the very top of your page.
More information about timeouts here: How do I increase timeout values

ASP 3.0 - Server.Execute Problems: Suffering from "ASP Amnesia" (Text Revised) [duplicate]

This question already has answers here:
ASP 3.0 - Server.Execute Problems: Suffering from "ASP Amnesia"
(3 answers)
Closed 8 years ago.
I'm using IIS 6, and created Two ASP 3.0 files:
-Main.asp
-Colors.asp
Main.asp
<%
If sColor = true then
Server.Execute "Colors.asp"
End If
'If sColor is true, Pops over to Colors.asp
'Then pops right back over to here again
'Once back here again, it has no idea what
'sRed or sBlue was at all...it's as if has
'been "blank slated"...sRed? Who the heck is sRed?
If sRed then
Response.Write "Color is Red"
End If
'Does not work...skips right over...
'Who is sRed? What is sRed?
'Oh well, keep on truckin'
%>
Colors.asp
<%
Dim sRed
sRed = instr(sString, "Red") >0
Dim sBlue
sBlue = instr(sString, "Blue") >0
Dim sGreen
sGreen = instr(sString, "Green") >0
%>
If one were to go into the Colors.asp file
above and modify/append it to read as follows:
<%
Dim sRed
sRed = instr(sString, "Red") >0
Dim sBlue
sBlue = instr(sString, "Blue") >0
Dim sGreen
sGreen = instr(sString, "Green") >0
If sRed then
Response.Write "Color is Red"
End If
%>
One would receive a screen with "Color is Red" when sColor was true over at Main.asp and sString
contained "Red." So I know she's getting over there, and also returning back over to Main.asp...but somehow she has no clue about those variables: sRed, sBlue, or sGreen that were dimmed over at Colors.asp. Once she gets back over to Main.asp she's clueless.
What gives? Why does she have ASP Amnesia once she gets back to Main.asp after having just been over at Colors.asp?
Edit
Dear YougoTiger,
I did what you suggested (I think) in Main.asp:
If sColor = true then
Server.Execute "Colors.asp"
If sRed then
Response.Write "Color is Red"
End If
End If
Nothing...still has ASP Amnesia- sRed Who?
Edit 2
Dear Bitwize,
I'm using Server.Execute instead of #include in order to free up the server. As you know #includes always get handled first in ASP, regardless of whether they are inside an If block. I'm basically trying to do dynamic server-side includes by way of Server.Execute, which can in fact be placed within an If block according to Microsoft:
Microsoft Support - Using the Server.Execute Method
The New ASP 3.0 Server Methods (Note: this is was originally http://www.15seconds.com/issue/010220.htm but that site is gone, the link is now a redirect to a numeric domain. Feel free to do your own search for the article by Paul Litwin and update this link if you can find it.)
A Look at ASP 3.0
The low-down on #includes
I still needing help with this, or a better explanation as to what is going on in my particular case. I've got a lot of dimmed variables over in that Color.asp file that I don't want the server to bother with if sColor=False.
Don't think it can be done without some changes. Using server.execute, the 2 pages are completely unaware of each others local variables (see proof below). An include would be better although you do loose the conditional ability.
The Request / Response Objects are shared by both files so you can work with those as need be. As far as sending variables between the files your only option is session or application variables. See below for code sample.
file 1:
dim localParent
localParent="start Value"
Response.write("Parent:"&localParent&"<br>")
Server.Execute "file.asp"
Response.write("Parent after Exec:"&localParent&"<br>")
file 2:
Response.write("Child:"&localParent&"<br>")
localParent = "Child changed"
Response.write("Child Afer set:"&localParent&"<br>")
Output:
Parent:start Value
Child:
Child Afer set:Child changed
Parent after Exec:start Value
Session variable passing:
file 1:
Dim myVar
'Do stuff
session("myVar") = myVar ' Save variable in session
Server.Execute "file.asp"
myVar = session("myVar") 'get changed variable back out of session
file 2:
Dim myLocalVar
myLocalVar = session("myVar") ' Get variable from session
'Do stuff to myLocalVar
session("myVar") = myLocalVar 'Put variable back into session for calling page to use.
I'm wondering if this might be a scope issue? I'm seeing two possible places that you're running into scope issues:
First, since your sRed in in another file, is scope limited to the file when you run a server.execute?
Second, since you're calling server.execute inside a if then, I'd expect that your other file has a scope of between the if and endif . You're then checking sRed AFTER the endif. Of the two, I'd think the second was more likely. Try your
If sRed then
Response.Write "Color is Red"
End If
block inside your first if then block, after the server.execute and see if this is the case.
Bitwize is completely correct - The calling page has no access to the executed pages local variables and neither does the executed page have access to the calling pages local variables. If you need to share local variables then you need to use include directives.
I have built entire ASP site architectures using the Server.Execute() technique and each executed script executes effectively in isolation. The only variable sharing you can do is via the Application or Session objects both of which have issues.
The only other way you might achieve your desired effect is via HTTP requests in your code to other scripts and have those scripts return JSON/XML structures with the relevant information, but IMHO this would add far more overhead than just using include directives.

Can you declare a variable in ASP classic like this?

I am trying to see if this can be done in classic ASP:
Dim myVar
myVar = <<< END
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>test</title>
</head>
<BODY>
END
I can do this in PHP, but I am not positivte if it can be done in ASP.
Problem is I need to handle the HTML output via a variable, and I don't want to go through the HTML and convert " to ""
EDIT:
I've found that this is called HEREDOC syntax in PHP.
Since its been asked, what I am trying to do is store HTML type tags (which may contain ', " characters which would otherwise break
myVar = "<stuff color="red">here</stuff>"
so I would need to fix it by replacing color="red" with color=""red""
PART OF THE PROBLEM:
I don't want to have to replace " with "" for the content as I assign it, I guess a HEREDOC syntax is not available for ASP classic.
OK FINE... :P
Since everyone is asking me WHY I am going about it this way, here is why, I have to support this old ASP code, I don't want to, but suddenly the scope of this old app changes that they want the contents (which used to be an HTML page) to be emailed, SO... I wanted to HEREDOC the HTML output, pass it to the mail function and have it email. Having said that, I know its sloppy, and I know it works better the other way, however this is what the job called for, I didn't want to re-write it, I just wanted to augment the output from HTML to HTML-EMAIL...
Hope that makes more sense ;)
The easiest thing to do would be to keep the HTML in a separate file, and then open that file using a TextStream object, reading the string into a variable.
No. One language's syntax isn't going to work in a different language. You can, however, assign a string literal to the variable:
Dim myVar
myVar = _
"<html xmlns=""http://www.w3.org/1999/xhtml"" lang=""en"" xml:lang=""en"">" & vbCrLf & _
"<head>" & vbCrLf & _
" <title>test</title>" & vbCrLf & _
"</head>" & vbCrLf & _
"" & vbCrLf & _
"<BODY>" & vbCrLf
I'm pretty sure you can't do exactly what you're asking here.
It might help, however, if you explained what you're trying to do. There may be some other way.
update:
You could consider putting your HTML fragments into seperate files. This would allow you to define them without having to do any reformatting of the HTML. In a similar manner you could put them into a database or even into resource files.
I'm still not 100% clear why you want these HTML fragments defined as variables, but these approaches would work.
there is no herodoc for asp :) gogo escape - its the only useable way

asp errors not displayed

I have moved an sql database from one server to a new one (detached/attached)
Now i experience some strange behavior as it does not work but NO error is displayed.
This is the code
<%
const database_dsn="PROVIDER=SQLNCLI10; SERVER=FR-2626\SQLLOP;DATABASE=Lop;Uid=admin-sql;Pwd=xxxx;"
response.write "Step 0//"
set conn=server.CreateObject("ADODB.Connection")
set RS=server.CreateObject("ADODB.Recordset")
conn.Open database_dsn
response.write "Step 1//"
req = "Select count(*) From tblArticleList"
response.write "Step 2//"
set RS = conn.Execute(req)
response.write "Step 3//"
%>
The program stops at Step 2; then nothing, no error is displayed...
I just don t know what to do..How can i get some error?
Thanks
Jonathan
Oh i partially found the answer for the error display.
In the Debug pane of the IIS directory configuration, Enable ASP debugging should NOT be checked...althought i thougth it should...
have you got your browser set to "show friendly http errors" this in conjuction with what you have already identified is the common causes I've had for not seeing an error message.
Shahkaplesh is also right that you can use Server.GetLastError() to get the last error that occurred but you shouldn't need to do this in this example.
When executing a query you don't use the "Set" command. I don't know why its not showing you anything, but your code should look more like this:
<%
const database_dsn="PROVIDER=SQLNCLI10; SERVER=FR-2626\SQLLOP;DATABASE=Lop;Uid=admin-sql;Pwd=xxxx;"
response.write("Step 0//")
set conn=server.CreateObject("ADODB.Connection")
set RS=server.CreateObject("ADODB.Recordset")
conn.Open database_dsn
response.write("Step 1//")
req = "Select count(*) From tblArticleList"
response.write("Step 2//")
RS = conn.Execute(req)
response.write("Step 3//")
%>
Yes, the parentheses on the "Response.Write" are optional. But I'm OCD like that and it makes troubleshooting a little easier.
You need to place error checking code to find out what the actual error might be.
I would suggest that you change you code like so:
<%
const database_dsn="PROVIDER=SQLNCLI10; SERVER=FR-2626\SQLLOP;DATABASE=Lop;Uid=admin- sql;Pwd=xxxx;"
'Its very important to add this line!!! '
On Error Resume Next
'Its very important to add this line!!! '
response.write "Step 0//"
set conn=server.CreateObject("ADODB.Connection")
set RS=server.CreateObject("ADODB.Recordset")
conn.Open database_dsn
if err.number<>0 then
response.write err.description
end if
response.write "Step 1//"
req = "Select count(*) From tblArticleList"
response.write "Step 2//"
set RS = conn.Execute(req)
if err.number<>0 then
response.write err.description
end if
response.write "Step 3//"
%>
And not to kick a dead horse but I'm doing something similar against an Oracle database and I've had two phantom problems I have yet to identify root cause but here's two things that made them go away.
1. Name all columns in a Query and Alias any that are calculated (sum, count, avg, etc.) So your query would become
req = "Select count(*) NumRows From tblArticleList"
2. Wrapping my query string in a call to cstr caused the result.EOF flag to be populated correctly rather than be returned with an empty or null value causing a simple DO WHILE NOT result.EOF Some Action LOOP to create an infinite loop until the web request timed out. So e.g.
response.write "Step 2//"
set RS = conn.Execute(cstr(req))
Nothing major just a couple tips if you get stuck and can't find out why. Follow the debugging advice above though, that's good info.
I think Server has a GetLastError method, which you can check to find out what error occurred while running any statement.
e.g. On error resume next
.... statement that could cause an error....
errorObject = Server.GetLastError()
For ASPError object, refer http://www.w3schools.com/asp/asp_ref_error.asp
Actually don't mean to be disagreeable, but yes you do need a Set there, as you are setting an object type and presumably wanting to use the return value at some point (if this wasn't just a test script which it looks like to me).
Also btw parentheses are not really correct there in Response.Write() as it does not return a value. They only happen to work on single parameter subs because you can put parentheses anywhere you like around expressions.
eg:
a = (b)
Response.Write ((("test"))&(1))

Resources