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.