Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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" )
%>


Reply With Quote
  #2 (permalink)  
Old August 13th, 2003, 01:12 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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.
Reply With Quote
  #3 (permalink)  
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.
Reply With Quote
  #4 (permalink)  
Old August 13th, 2003, 03:39 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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.
Reply With Quote
  #5 (permalink)  
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....

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:18 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.