Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / May 2005

Tip: Looking for answers? Try searching our database.

Web Service And Datareader

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Perona - 16 May 2005 21:00 GMT
   Hi all,
   I have a web service that connects to a SQL Server database and return
an sqlDataReader Object.
   When launch the web service in the web browser, this exception is
thrown:
   "Object Reference not established" from System.NullReferenceException.

   If I change the web service to return a integer value, its run ok.
   I'm Importing the System.Data.SqlClient namespace.
   What's the problem?

   Thanks.
Mickey Williams [C# MVP] - 17 May 2005 00:04 GMT
>    I have a web service that connects to a SQL Server database and return
> an sqlDataReader Object.

You can't do that. What does an XML-serialized SqlDataReader look like? You
can (probably) return the data, but not the reader.

Signature

Mickey Williams
C# MVP, MCT, Author 'Visual C# Core Reference', MS Press
http://www.servergeek.com

Chad Z. Hower aka Kudzu - 17 May 2005 07:12 GMT
"David Perona" <david.perona@telefonica.net> wrote in news:uJOEBHlWFHA.1404
@TK2MSFTNGP09.phx.gbl:
>     I have a web service that connects to a SQL Server database and return
> an sqlDataReader Object.
>     When launch the web service in the web browser, this exception is
> thrown:
>     "Object Reference not established" from System.NullReferenceException.

Return a type of DataSet instead, then create a DataAdaptor and call Fill
using the command before you get the reader. This will do what you want.

[WebMethod]
public DataSet GetCustomers () {
 DataSet xResult = new DataSet();
   xConnection.Open();
   FbDataAdapter xAdapter = new FbDataAdapter("select * from \"Customer\"",
xConnection);
   xAdapter.Fill(xResult);
 return xResult;
}

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
     "Programming is an art form that fights back"

Blog: http://blogs.atozed.com/kudzu
David Perona - 17 May 2005 08:13 GMT
"David Perona" escribió:

>     Hi all,
>     I have a web service that connects to a SQL Server database and return
[quoted text clipped - 8 lines]
>
>     Thanks.

  Oouchh!! Sorry :)
  Datareader need a opened connection to navigate throw the records... Ups ;)
Martin - 18 May 2005 17:17 GMT
Hi,
I have the same problem, but my code doesn't close the connection, after
return the dataReader object.
Can You tell me, what you did? Thanks-

Martin

> "David Perona" escribió:
>
[quoted text clipped - 13 lines]
>    Oouchh!! Sorry :)
>    Datareader need a opened connection to navigate throw the records... Ups ;)
KellyL - 28 May 2005 15:42 GMT
I noticed that the ExecuteReader method of the Connection object has an
optional parameter to automatically close the connection after the DataReader
is returned.  You might try that.

> Hi,
> I have the same problem, but my code doesn't close the connection, after
[quoted text clipped - 23 lines]
> >    Datareader need a opened connection to navigate throw the records...
> Ups ;)
Ravichandran J.V. - 19 May 2005 06:36 GMT
A DataReader can be read only over an open connection. So, you would be
better off reading the data from the SQLServer into a dataset in the web
service and then then web service returning the dataset.

with regards,

J.V.

>     Hi all,
>     I have a web service that connects to a SQL Server database and return
[quoted text clipped - 8 lines]
>
>     Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.