Beginner Web Service error: Object reference not setHello,

Discussion in 'ASP .Net Web Services' started by Derek Correia, Sep 8, 2005.

  1. Hello,

    I'm just getting started with web services. I've written one that takes
    an integer and searches an Oracle database for that customer ID. I want
    it to return all records with that customer ID. Below is the code of
    the ASMX page:

    ---------------

    <%@ WebService Language="VB" Class="WebCenter" %>
    Imports System.Web.Services
    Imports System.Data
    Imports System.Data.OracleClient
    Imports System.Configuration


    Public Class WebCenter
    Private Function GetDataSet(strSQL as String) as DataSet

    Dim oraConn As OracleConnection = New OracleConnection("Data
    Source=ORASRV;Integrated
    Security=no;user=WEBSERVICE;password=WEBSERVICE;")
    Dim oraCMD As OracleCommand = New OracleCommand(strSQL , oraConn)

    oraConn.Open()

    Dim myDataAdapter as OracleDataAdapter
    myDataAdapter.SelectCommand = oraCMD

    Dim myDataSet as New DataSet()
    myDataAdapter.Fill(myDataSet)
    oraConn.Close()

    Return myDataSet
    End Function



    <WebMethod()> Public Function FindMember(memid as Integer) as
    DataSet
    dim strSQL as string
    strSQL = "SELECT * FROM DW_USERS where SUBSCRIBER_ID=" & memid
    Return GetDataSet(strSQL)
    End Function
    End Class


    ------------

    When testing the above code using HTTP get from the localhost, I get
    the following error:

    System.NullReferenceException: Object reference not set to an instance
    of an object.
    at WebCenter.GetDataSet(String strSQL)
    at WebCenter.FindMember(Int32 memid)

    Is there something I am doing wrong? This is on a Windows 2k server
    with .Net framework 1.1 installed. Thank you.

    -Derek
     
    Derek Correia, Sep 8, 2005
    #1
    1. Advertising

  2. Derek  Correia

    Hadi Hariri Guest

    Have you tried tracing? You're referencing an object that you have not
    created or has been freed. Put a breakpoint and you'll hit it instantly.
     
    Hadi Hariri, Sep 9, 2005
    #2
    1. Advertising

  3. Thank you Hadi. I found the issue, and it was that I was doing string
    operations on a string that was not properly defined. The breakpoint
    threw it right in my face. Thanks again!
     
    Derek Correia, Sep 9, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parthiv Joshi
    Replies:
    2
    Views:
    702
    Kalyan
    Jul 2, 2004
  2. Suresh Kojhani
    Replies:
    1
    Views:
    2,398
    Anushi
    Jul 29, 2004
  3. Pedro Correia
    Replies:
    0
    Views:
    635
    Pedro Correia
    Jul 25, 2003
  4. Kiran
    Replies:
    3
    Views:
    765
  5. Replies:
    1
    Views:
    488
    Mark Rae [MVP]
    Sep 20, 2007
Loading...

Share This Page