code execution


S

solomon_13000

The problem with the code bellow is that suppose I change the valid
database name from stelladb.mdb to an invalid database name stella.mdb,
what happens is the following statement gets executed:

response.write "<center><font class='error'>Error: Username is
unavailable</font></center><br><br>"

Response.Write "<center><font class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"

By right only the statement bellow is suppose to get executed:

Response.Write "<center><font class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"

How do I solve the problem:


Complete code:


on error resume next
set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/db/upload/stelladb.md") & ";"
set rs = Server.CreateObject("ADODB.Recordset")
conn.qDupUser p1,rs
If not rs.eof then
If rs(0) = 1 then
response.write "<center><font class='error'>Error: Username is
unavailable</font></center><br><br>"
session("duplicate") = "true"
else
session("duplicate") = "false"
end if
Else
response.write "<center><font class='error'>Error: No records
returned</font></center><br><br>"
End if
If Err.number <> 0 then
Response.Write "<center><font class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
Else
conn.close
set conn = nothing
if session("duplicate") = "false" then
InsertQueryString p1,p2,p3
end if
End if
on Error goto 0


Sub InsertQueryString(p1,p2,p3)
arParms = Array(p1,p2,p3)
sql = "INSERT INTO Account([Username],[Password],[Type]) VALUES(?,?,?)"

RunQueryString sql, arParms
End Sub
 
Ad

Advertisements

B

Bob Barrows [MVP]

solomon_13000 said:
The problem with the code bellow is that suppose I change the valid
database name from stelladb.mdb to an invalid database name
stella.mdb,

So stella.mdb is an actual database, so your conn.open statement does not
throw an error?
Change the code as shown below:
what happens is the following statement gets executed:

response.write "<center><font class='error'>Error: Username is
unavailable</font></center><br><br>"

Response.Write "<center><font class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"

By right only the statement bellow is suppose to get executed:

Response.Write "<center><font class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"

How do I solve the problem:


Complete code:


on error resume next
set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/db/upload/stelladb.md") & ";"

if err said:
response.write "<center><font class='error'>Error: Username is
unavailable</font></center><br><br>"
session("duplicate") = "true" else
set rs = Server.CreateObject("ADODB.Recordset")
conn.qDupUser p1,rs
If not rs.eof then
If rs(0) = 1 then
response.write "<center><font class='error'>Error: Username is
unavailable</font></center><br><br>"
session("duplicate") = "true"
else
session("duplicate") = "false"
end if
Else
response.write "<center><font class='error'>Error: No records
returned</font></center><br><br>"
End if
If Err.number <> 0 then
Response.Write "<center><font class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
Else
conn.close
set conn = nothing
if session("duplicate") = "false" then
InsertQueryString p1,p2,p3
end if
End if

End if
on Error goto 0


Sub InsertQueryString(p1,p2,p3)
arParms = Array(p1,p2,p3)
sql = "INSERT INTO Account([Username],[Password],[Type])
VALUES(?,?,?)"

RunQueryString sql, arParms
End Sub
 
S

solomon_13000

valid database name:stelladb.mdb
invalid database name: stella.mdb

It does throw an error message using an invalid db name:

Response.Write "<center><font class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"

but the code also displays the following error msg which is not suppose
to be displayed:

response.write "<center><font class='error'>Error: Username is
unavailable</font></center><br><br>"
 
Ad

Advertisements

B

Bob Barrows [MVP]

solomon_13000 said:
valid database name:stelladb.mdb
invalid database name: stella.mdb

It does throw an error message using an invalid db name:

Response.Write "<center><font class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"

but the code also displays the following error msg which is not
suppose to be displayed:

response.write "<center><font class='error'>Error: Username is
unavailable</font></center><br><br>"
Well change it to display the message you want it to display in the if err
<> 0 then block. (hopefully, you made the changes I suggested - it will be
really helpful if you post your code revisions in any followups to this).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top