object reference error

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default object reference error

    Can someone please help. I am running locally XP, IIS5. Am trying forms
    authentication with no luck in one area. I am using the following script to
    check username and password against access2000 db via stored procedures.
    <code> <%@ Import Namespace='System.Data' %> <%@ Import
    Namespace='System.Data.OleDb' %> <script runat='server'> sub Login(obj as
    object, e as eventargs) dim intID as integer = 0 dim Conn as new
    OleDbConnection('my conn here') dim objCmd as OleDbCommand = new
    OleDbCommand('spValidateUser', Conn) objCmd.CommandType =
    CommandType.StoredProcedure dim objReader as OleDbDataReader 'set
    parameters for stored procedure dim objParam as OleDbParameter
    objParam = objCmd.Parameters.Add('@UserName', OleDbType.BSTR)
    objParam.Direction = ParameterDirection.Input objParam.Value =
    tbUserName.Text objParam = objCmd.Parameters.Add('@Password',
    OleDbType.BSTR) objParam.Direction = ParameterDirection.Input
    objParam.Value = tbPassword.Text try
    objCmd.Connection.Open() objReader = objCmd.ExecuteReader do
    while objReader.Read intID = objReader.GetInt32(0).ToString
    loop catch ex as OleDbException lblMessage.Text = ex.Message
    finally objReader.Close objCmd.Connection.Close()
    end try if intID <> 0 then
    FormsAuthentication.SetAuthCookie(intID, false)
    Response.redirect('default.aspx') else lblMessage.Text = '<font
    color=red>Sorry, invalid username or password!</font><p>' end if end
    sub </script> </code> I get the following error (line 42 is the error) in
    debug mode: Object reference not set to an instance of an object. Exception
    Details: System.NullReferenceException: Object reference not set to an instance
    of an object. Source Error: Line 40: lblMessage.Text = ex.Message Line 41:
    finally Line 42: objReader.Close Line 43: objCmd.Connection.Close() Line 44:
    end try Can someone please help before I rip my hair out! Cheers

    JoelTSRoberts Guest

  2. Similar Questions and Discussions

    1. Object Reference Error. Pls Help!
      Hi, I'm having a major issue with one of the custom contols I've created. Basically, it consists of a dropdown, button and some textboxes for the...
    2. Mysterious Error: Object reference not set to an instance of an object
      Hi There! I'm having a mysterious error right after I login using Forms Authentication in my ASP.NET app. Below is the error... Exception...
    3. Error msg: Bad foreign object reference
      I am using Acrobat Std v. 6.0.1 11/3/2003 to create PDF files from MS Word files or web pages and email them to others over the Internet. Recipients...
    4. HELP! Error Loading ASPX : Object Reference not set to an instance object
      Hello, When i run my aspx i get this weird error: System.NullReferenceException: Object reference not set to an instance of an object. at...
    5. Object reference not set to an instance of an object. .......... Error .... Please Help
      Hi, I am facing a problem, and i don't know why the error is being generated. I am updating a datagrid with an XML file. My code is ...
  3. #2

    Default Re: object reference error

    The error normally means that you are calling a web control (ie a text box)
    in the code that does not exist on the page. Check that the names of the
    fields are all correct and that they are webcontrols (denoted by a asp:) in
    front of them and that they have a runat=server attribute.

    --
    Regards

    Paul Whitham
    Macromedia Certified Professional for Dreamweaver MX2004
    Valleybiz Internet Design
    [url]www.valleybiz.net[/url]

    Team Macromedia Volunteer for Ultradev/Dreamweaver MX
    [url]www.macromedia.com/support/forums/team_macromedia[/url]

    "JoelTSRoberts" <webforumsuser@macromedia.com> wrote in message
    news:d17q67$rk3$1@forums.macromedia.com...
    > Can someone please help. I am running locally XP, IIS5. Am trying forms
    > authentication with no luck in one area. I am using the following script
    to
    > check username and password against access2000 db via stored procedures.
    > <code> <%@ Import Namespace='System.Data' %> <%@ Import
    > Namespace='System.Data.OleDb' %> <script runat='server'> sub Login(obj
    as
    > object, e as eventargs) dim intID as integer = 0 dim Conn as
    new
    > OleDbConnection('my conn here') dim objCmd as OleDbCommand = new
    > OleDbCommand('spValidateUser', Conn) objCmd.CommandType =
    > CommandType.StoredProcedure dim objReader as OleDbDataReader
    'set
    > parameters for stored procedure dim objParam as OleDbParameter
    > objParam = objCmd.Parameters.Add('@UserName', OleDbType.BSTR)
    > objParam.Direction = ParameterDirection.Input objParam.Value =
    > tbUserName.Text objParam = objCmd.Parameters.Add('@Password',
    > OleDbType.BSTR) objParam.Direction = ParameterDirection.Input
    > objParam.Value = tbPassword.Text try
    > objCmd.Connection.Open() objReader = objCmd.ExecuteReader
    do
    > while objReader.Read intID = objReader.GetInt32(0).ToString
    > loop catch ex as OleDbException lblMessage.Text =
    ex.Message
    > finally objReader.Close objCmd.Connection.Close()
    > end try if intID <> 0 then
    > FormsAuthentication.SetAuthCookie(intID, false)
    > Response.redirect('default.aspx') else lblMessage.Text =
    '<font
    > color=red>Sorry, invalid username or password!</font><p>' end if
    end
    > sub </script> </code> I get the following error (line 42 is the error)
    in
    > debug mode: Object reference not set to an instance of an object.
    Exception
    > Details: System.NullReferenceException: Object reference not set to an
    instance
    > of an object. Source Error: Line 40: lblMessage.Text = ex.Message
    Line 41:
    > finally Line 42: objReader.Close Line 43: objCmd.Connection.Close()
    Line 44:
    > end try Can someone please help before I rip my hair out! Cheers
    >

    Paul Whitham TMM Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139