Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2003, 05:42 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default catching error

...not sure why. new to .net, read most of wrox beginning asp.net w/ vb.net. too much stuff is unexplained.

here's my code. i believe that the the problem exists in the catch section, just after i assign a value to Sesion("Email"). all other Session variables are not set, except Session("Error"), which informs me of the catch.:

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Oledb" %>
<%
Dim strCon as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & _
  "D:\Inetpub\wwwroot\Network.mdb;"

Dim sql as String = "SELECT pwdPassword FROM tblPasswords WHERE memEmail='" & _
  LCase(Trim(Request("txtLogEmail"))) & "';"

Dim con as New OledbConnection( strCon )

con.Open()

Try
    Dim cmd as New OledbCommand( sql, con )

    Dim rdr as OledbDataReader
    rdr = cmd.ExecuteReader()

    If rdr.Read()=False Then
         Session("Error") = "Email address not registered."
    elseif rdr("pwdPassword") <> Trim(Request("txtLogPassword")) then
          Session("Error") = "Password incorrect."
    Else
     Session("Email") = LCase(Trim(Request("txtLogEmail")))
     rdr.Close()

     sql = "SELECT * FROM tblMembers WHERE memEmail='" & session("Email") & "';"

     Dim cmd2 as New OledbCommand( sql, con )
     Dim rdr2 = cmd2.ExecuteReader()
             Session("Name") = rdr2("memName")
            Session("Alias") = rdr2("memAlias")
            Session("MI") = rdr2("memMI")
            Session("Surname") = rdr2("memSurname")
            Session("Address") = rdr2("memAddress")
            Session("City") = rdr2("memCity")
            Session("AC") = rdr2("memAC")
            Session("Telephone") = rdr2("memTelephone")
            Session("URL") = rdr2("memURL")
            Session("Width")= rdr2("memWidth")
            Session("Blurbs") = rdr2("memBlurbs")
        rdr2.Close()
    End if
Catch
    Session("Error") = "TROUBLE! :("
End Try
con.Close()
sql = ""
Response.Redirect( "index.aspx" )
%>


 
Old August 13th, 2003, 01:12 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I think the problem is in the Try part. If the Session("Error") gets set, it means that somewhere in the Try block an error is thrown.

Two ways to find out:

1. Debug. Step line by line through the Try block
2. Comment out the Try Catch construct temporarily, and see where the code crashes.

Maybe the SELECT statement does not return a record or generates an error.....

HtH

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 13th, 2003, 01:34 AM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you are correct; that's the whole point of a try block - to catch errors and deal with them.

i believe that the problem lies in the data objects, specifically the dataReader object. i suspect that it is because the dataReader, unlike the ADO recordset object, does not point to the first record when it is instantiated, but to BOF. additionally, i am not yet familiar with the java-like structure of .net, and its documentation.

it appears that the authors of this object intended that the user traverse the records by using a loop. in my case i have need for but a single field, and figure it useless to deploy a looping structure when it is hardly necessary. i recently discovered that the Read function traverses the records within the dataReader object.

this is not one of the better books that i have purchased, and i would not recommend beginning asp.net with vb.net to anyone who needs to understand the architecture. it is simply insufficiently thorough.
 
Old August 13th, 2003, 03:39 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Try Catch blocks are designed to catch errors at runtime. At design time they can be a pain sometimes as you don't always now what error you're dealing with. So, either you'll need to run the code in debug mode, so you can examine the error in the Catch block, or don't use Try / Catch temporarily and see what error occurs.

When dealing with a single record in a DataReader, simply use its Read method in an If statement:

Code:
If myReader.Read() Then
    ' The Read method makes sure you are 
    'pointing to the first record now
    ' Use the reader here.
End If
HtH

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 13th, 2003, 08:29 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thx. it's fixed now. still, it has been a long while since i touched anything java, and migrating to .net will take more than a refresher. thk microsoft for sdk documentation, where i found that which resolved my problems thus far.

thx for responding....





Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching a SQLException error digriz60 ASP.NET 1.0 and 1.1 Basics 5 January 14th, 2008 03:14 PM
Catching Up John Kauffman BOOK: Beginning ASP.NET 2.0 and Databases 2 October 2nd, 2006 05:04 PM
catching error darkhalf Javascript 4 December 14th, 2005 01:44 PM
Error catching and throwing - code rjp Access VBA 1 August 25th, 2004 08:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.