473,574 Members | 3,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error handling

One problem with the code bellow is after this code

conn.qDupUser p1,rs

I added:

set rs = nothing

to test the error handling capability.

What happen is the code bellow gets executed

If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else

along with the code bellow

If Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
THE CODE:
If request.querySt ring("Action") = 2 then
p1 = Trim(request.fo rm("username") )
p2 = Trim(request.fo rm("password") )
p3 = Trim(request.fo rm("type"))
If (p1 <> "" and p2 <> "") AND (Len(p1)<=12 and Len(p2)<=12) then
on error resume next
set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
Server.MapPath( "/db/upload/stelladb.mdb") & ";"
set rs = Server.CreateOb ject("ADODB.Rec ordset")
conn.qDupUser p1,rs
set rs = nothing
If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else
arParms = Array(p1,p2,p3)
sql = "INSERT INTO Account([Username],[Password],[Type]) VALUES(?,?,?)"
RunQueryString sql, arParms
End if
if Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
Else
response.write "<center><f ont class='error'>E rror: Invalid username or
password</font></center><br><br> "
End if
End if
How do I solve the problem?

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Jun 22 '06 #1
4 1893

Eugene Anthony wrote:
One problem with the code bellow is after this code

conn.qDupUser p1,rs

I added:

set rs = nothing

to test the error handling capability.

What happen is the code bellow gets executed

If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else

along with the code bellow

If Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
THE CODE:
If request.querySt ring("Action") = 2 then
p1 = Trim(request.fo rm("username") )
p2 = Trim(request.fo rm("password") )
p3 = Trim(request.fo rm("type"))
If (p1 <> "" and p2 <> "") AND (Len(p1)<=12 and Len(p2)<=12) then
on error resume next
set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
Server.MapPath( "/db/upload/stelladb.mdb") & ";"
set rs = Server.CreateOb ject("ADODB.Rec ordset")
conn.qDupUser p1,rs
set rs = nothing
If rs(0) = 1 then


I'm not quite sure what your problem is, because you haven't exactly
described it very well, but in the 4 lines above, you have declared a
recordset object, opened it, set it to nothing and then tried to
reference it.

Obviously, since you have set rs = nothing, anything that belongs to rs
is also set to nothing, including rs(0).

--
Mike Brind

Jun 22 '06 #2
I purposely set rs = nothing

to test the error handling capability and what happen is the code
bellow gets executed

If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else

followed by the code bellow

If Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0

so I am getting two error msg which is wrong. Only one error msg is to
be displayed.
Eugene Anthony wrote:
One problem with the code bellow is after this code

conn.qDupUser p1,rs

I added:

set rs = nothing

to test the error handling capability.

What happen is the code bellow gets executed

If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else

along with the code bellow

If Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
THE CODE:
If request.querySt ring("Action") = 2 then
p1 = Trim(request.fo rm("username") )
p2 = Trim(request.fo rm("password") )
p3 = Trim(request.fo rm("type"))
If (p1 <> "" and p2 <> "") AND (Len(p1)<=12 and Len(p2)<=12) then
on error resume next
set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
Server.MapPath( "/db/upload/stelladb.mdb") & ";"
set rs = Server.CreateOb ject("ADODB.Rec ordset")
conn.qDupUser p1,rs
set rs = nothing
If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else
arParms = Array(p1,p2,p3)
sql = "INSERT INTO Account([Username],[Password],[Type]) VALUES(?,?,?)"
RunQueryString sql, arParms
End if
if Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
Else
response.write "<center><f ont class='error'>E rror: Invalid username or
password</font></center><br><br> "
End if
End if
How do I solve the problem?

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***


Jun 23 '06 #3
On Error Resume Next tells the VBScript engine to ignore errors and
continue with the next line of code. Details of the last error
encountered are stored in the Err object. Previous error information
is lost. On Error Goto 0 switches off On Error Resume Next, so code
continues executing normally until it reaches another error.

More information:
http://blogs.msdn.com/ericlippert/ar...19/217244.aspx

--
Mike Brind

solomon_13000 wrote:
I purposely set rs = nothing

to test the error handling capability and what happen is the code
bellow gets executed

If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else

followed by the code bellow

If Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0

so I am getting two error msg which is wrong. Only one error msg is to
be displayed.
Eugene Anthony wrote:
One problem with the code bellow is after this code

conn.qDupUser p1,rs

I added:

set rs = nothing

to test the error handling capability.

What happen is the code bellow gets executed

If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else

along with the code bellow

If Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
THE CODE:
If request.querySt ring("Action") = 2 then
p1 = Trim(request.fo rm("username") )
p2 = Trim(request.fo rm("password") )
p3 = Trim(request.fo rm("type"))
If (p1 <> "" and p2 <> "") AND (Len(p1)<=12 and Len(p2)<=12) then
on error resume next
set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
Server.MapPath( "/db/upload/stelladb.mdb") & ";"
set rs = Server.CreateOb ject("ADODB.Rec ordset")
conn.qDupUser p1,rs
set rs = nothing
If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else
arParms = Array(p1,p2,p3)
sql = "INSERT INTO Account([Username],[Password],[Type]) VALUES(?,?,?)"
RunQueryString sql, arParms
End if
if Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
Else
response.write "<center><f ont class='error'>E rror: Invalid username or
password</font></center><br><br> "
End if
End if
How do I solve the problem?

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***


Jun 23 '06 #4

"solomon_13 000" <so***********@ yahoo.com> wrote in message
news:11******** *************@i 40g2000cwc.goog legroups.com...
I purposely set rs = nothing

to test the error handling capability and what happen is the code
bellow gets executed

If rs(0) = 1 then
Earlier in your code you set On Error Resume Next.

This line fails but that doesn't imply the whole If ... End If block is
skipped. Code execution just falls into the 'Then' portion and executes
that. I can't say whether it's guaranteed always to behave that way but at
least in VBScript it fairly certain.
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else

followed by the code bellow

If Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0

so I am getting two error msg which is wrong. Only one error msg is to
be displayed.

Frankly Error handling in VBScript stinks. Using a blanket On Error Resume
Next can often to lead to all sorts of strange an seemingly inexplicable
behaviour.

If you really must use it extract the specific lines that really need this
(there are usually only one or two lines that actually need this) and move
them into their own function. You can place the On Error Resume Next in
those functions.

Eugene Anthony wrote:
One problem with the code bellow is after this code

conn.qDupUser p1,rs

I added:

set rs = nothing

to test the error handling capability.

What happen is the code bellow gets executed

If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else

along with the code bellow

If Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
THE CODE:
If request.querySt ring("Action") = 2 then
p1 = Trim(request.fo rm("username") )
p2 = Trim(request.fo rm("password") )
p3 = Trim(request.fo rm("type"))
If (p1 <> "" and p2 <> "") AND (Len(p1)<=12 and Len(p2)<=12) then
on error resume next
set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
Server.MapPath( "/db/upload/stelladb.mdb") & ";"
set rs = Server.CreateOb ject("ADODB.Rec ordset")
conn.qDupUser p1,rs
set rs = nothing
If rs(0) = 1 then
response.write "<center><f ont class='error'>E rror: Username is
unavailable</font></center><br><br> "
conn.close
set conn = nothing
else
arParms = Array(p1,p2,p3)
sql = "INSERT INTO Account([Username],[Password],[Type]) VALUES(?,?,?)"
RunQueryString sql, arParms
End if
if Err.number <> 0 then
Response.Write "<center><f ont class='error'>" & Err.number & ":" &
Err.Description & "</font></center><br>"
end if
on Error goto 0
Else
response.write "<center><f ont class='error'>E rror: Invalid username or
password</font></center><br><br> "
End if
End if
How do I solve the problem?

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***

Jun 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3262
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error handling within classes. Just hoping to hear some programmer's thoughts on error handling.
12
6658
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that assert could be used to start an interactive debugger automatically. How do I realize that on a Linux machine using gcc?
21
4390
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a...
3
2843
by: Stefan Johansson | last post by:
Hi all I'am moving from Visual Foxpro and have a question regarding "best practice" error handling in vb .net. In VFP I have always used a "central" error handling object in order to have a easy and reusable way of handling all errors in a program. The VB 6 coding examples I have seen there has always been error handling code in each...
4
1923
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I haven't placed error handling code). When I run my app from the IDE, the unhandled errors are caught by the error handling code in my Sub Main...
1
9917
by: Metal Dave | last post by:
I do not understand the error handling of SQL Server here. Any error in bulk insert seems to halt the current T-SQL statement entirely, rendering it impossible to log an error. The first statement below executes as expected, and were I to replace "print" with something meaningful I could do some useful error handling. The second statement just...
10
2277
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on that ID, otherwise...
1
2245
by: pob | last post by:
>From a form I have some code that calls 4 modules frmMain 1 mod 2 mod 3 mod 4 mod If mod 1 experiences an error the error handling works fine within mod 1 and writes out the error to a table, but the other modules still get
35
3755
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks gets about 3 or so. It also gets very awkward in nested loops, where you want to check for normal loop processing in the loop condition, not...
0
11572
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access Security, but I'll start with something short and simple This code was written in Access 2003 but should be valid in Access 2000 By default, when you...
0
7764
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8110
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8138
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6514
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5658
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3775
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1102
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.