Dataset returning Null in VB 2008

Discussion in 'ASP .Net Web Services' started by Nab, Sep 10, 2008.

  1. Nab

    Nab Guest

    This code for a webservice is returning a dataset with a Null value (by
    throwing a System.NullReferenceException) when using VB2008. The GUI is used
    to establish a connection and adapter to an MS Access database (with a table
    named EstateAgents). I had no problem when used this code with VB2005. Here's
    the code:

    <WebMethod()> _
    Public Function GetEstateAgents() As DataSet
    Dim estateDataset As DataSet = New DataSet
    estateOleAdapter.Fill(estateDataset, "EstateAgents")
    Return estateDataset
    estateOleConnection.Close()
    End Function

    Any suggestions will be gratefully received.

    --
    UK
    Nab, Sep 10, 2008
    #1
    1. Advertising

  2. "Nab" <> wrote in message
    news:...
    > This code for a webservice is returning a dataset with a Null value (by
    > throwing a System.NullReferenceException) when using VB2008. The GUI is
    > used
    > to establish a connection and adapter to an MS Access database (with a
    > table
    > named EstateAgents). I had no problem when used this code with VB2005.
    > Here's
    > the code:
    >
    > <WebMethod()> _
    > Public Function GetEstateAgents() As DataSet
    > Dim estateDataset As DataSet = New DataSet
    > estateOleAdapter.Fill(estateDataset, "EstateAgents")
    > Return estateDataset
    > estateOleConnection.Close()
    > End Function


    Exactly where is the NullReferenceException occurring? Please post the
    complete exception. Also, what do you mean that the GUI establishes the
    connection? Is the GUI establishing the connection and the service trying to
    use it? Why would that work?

    --
    John Saunders | MVP - Connected System Developer
    John Saunders, Sep 10, 2008
    #2
    1. Advertising

  3. Nab

    Nab Guest

    I hope you could shed some light on this John. What I mean by “The GUI
    establishes the connection) is that I dragged the OleDbConnection icon on the
    toolbox to the design area to establish the connection (i.e. not in code).
    This process creates a connection object and an OleDbAdapter object (which I
    named estateOleAdapter as you can see in my web service code). I also tried
    to establish the connection and adapter in code but continue to have the same
    problem.

    Whenever I try to consume this service (using a web or even a windows
    application this exception comes up):

    System.ServiceModel.FaultException was unhandled by user code
    Message="System.Web.Services.Protocols.SoapException: Server was unable to
    process request. ---> System.NullReferenceException: Object reference not set
    to an instance of an object. at
    WebServiceLiverpoolUKEstateAgents.Service1.GetEstateAgents() in
    C:\Hope\modules i teach\web services\handout
    exercises\chapter5\WebServiceLiverpoolUKEstateAgents\WebServiceLiverpoolUKEstateAgents\LiverpoolUKEstateAgents.asmx.vb:line
    29 --- End of inner exception stack trace ---"
    Source="mscorlib"
    StackTrace:
    Server stack trace: at
    System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime
    operation, ProxyRpc& rpc) at
    System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean
    oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs,
    TimeSpan timeout) at
    System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean
    oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at
    System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
    methodCall, ProxyOperationRuntime operation) at
    System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: at
    System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
    reqMsg, IMessage retMsg) at
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,
    Int32 type) at
    ClientLiverpoolUKEstateAgents.WebServiceLiverpoolUKEstateAgents.Service1Soap.GetEstateAgents()
    at
    ClientLiverpoolUKEstateAgents.WebServiceLiverpoolUKEstateAgents.Service1SoapClient.GetEstateAgents()
    in C:\Hope\modules i teach\web services\handout
    exercises\chapter5\ClientLiverpoolUKEstateAgents\ClientLiverpoolUKEstateAgents\Service
    References\WebServiceLiverpoolUKEstateAgents\Reference.vb:line 59 at
    ClientLiverpoolUKEstateAgents._Default.form1_Load(Object sender, EventArgs e)
    in C:\Hope\modules i teach\web services\handout
    exercises\chapter5\ClientLiverpoolUKEstateAgents\ClientLiverpoolUKEstateAgents\Default.aspx.vb:line
    19 at System.Web.UI.Control.OnLoad(EventArgs e) at
    System.Web.UI.Control.LoadRecursive() at
    System.Web.UI.Control.LoadRecursive() at
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
    Boolean includeStagesAfterAsyncPoint)
    InnerException:

    This is the code (inserted in a command’s click procedure) that I used to
    consume the service:

    Dim eaService As New WebServiceLiverpoolUKEstateAgents.Service1SoapClient

    'Supply the dataset to become the DataGrid's datasource
    'dgEstateAgents.DataSource = eaService.GetEstateAgents

    dgEstateAgents.DataSource = eaService.GetEstateAgents

    'Bind the data to the datagrid by transferring
    'it from the dataset to the datagrid

    dgEstateAgents.DataBind()

    The dgEstateAgents is the name of the datagrid which I created using the
    GUI. When adding a reference, I tried “Add Service Reference†and I also
    tried “Add Web Referenceâ€, neither worked.

    To ensure that my web service is well connected to my Access database, I
    would sometimes click on the Data icon on the menu bar and select Preview
    Data and then click to populate the dataset. Sometimes this results in the
    display of the database’s table. However, when I try to do same thing other
    times I get a window that says: "Value cannot be null. Parameter name:
    serviceProvider" which leads me to conclude that the dataset is empty. If I
    close that web service and relaunch it I don’t get this "Value cannot be
    null. Parameter name: serviceProvider" error!!


    In either case, my client application halts on this line
    dgEstateAgents.DataSource = eaService.GetEstateAgents
    every time I try to consume the service and throws the exception listed above.

    The operation system I use is Vista (business edition).

    When I used VS 2005 in the past I had no such errors and the web service was
    consumed without any problems. So, I am really clueless here!




    --
    UK


    "John Saunders" wrote:

    > "Nab" <> wrote in message
    > news:...
    > > This code for a webservice is returning a dataset with a Null value (by
    > > throwing a System.NullReferenceException) when using VB2008. The GUI is
    > > used
    > > to establish a connection and adapter to an MS Access database (with a
    > > table
    > > named EstateAgents). I had no problem when used this code with VB2005.
    > > Here's
    > > the code:
    > >
    > > <WebMethod()> _
    > > Public Function GetEstateAgents() As DataSet
    > > Dim estateDataset As DataSet = New DataSet
    > > estateOleAdapter.Fill(estateDataset, "EstateAgents")
    > > Return estateDataset
    > > estateOleConnection.Close()
    > > End Function

    >
    > Exactly where is the NullReferenceException occurring? Please post the
    > complete exception. Also, what do you mean that the GUI establishes the
    > connection? Is the GUI establishing the connection and the service trying to
    > use it? Why would that work?
    >
    > --
    > John Saunders | MVP - Connected System Developer
    >
    >
    Nab, Sep 10, 2008
    #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. Replies:
    5
    Views:
    26,428
    Mike Schilling
    Mar 29, 2006
  2. shapper

    Windows 2008 and SQL 2008

    shapper, Dec 8, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    323
    Mark Fitzpatrick
    Dec 8, 2007
  3. Replies:
    0
    Views:
    483
  4. Barry Kelly
    Replies:
    0
    Views:
    390
    Barry Kelly
    Jan 9, 2008
  5. jason
    Replies:
    13
    Views:
    847
    John B. Matthews
    May 14, 2010
Loading...

Share This Page