Return a SqlDataReder

A

Asier

Hello,

I've a webService thar read from my database and let results in a
SqlDataReader. I want to return this datreader to my ASP.NET page but it
fail.
This is my code:
***************************

Dim cnConexion As New SqlConnection("..................")

<WebMethod()> Public Function fLeerTodasCIAs() As SqlDataReader

Dim drCIAS As SqlDataReader

Dim cmd As New SqlCommand("spCIASLeerTodas", cnConexion)

cmd.CommandType = CommandType.StoredProcedure

cnConexion.Open()

drCIAS = cmd.ExecuteReader(CommandBehavior.CloseConnection)

drCIAS.Close()

End Function

**************************

What is the problem?? thanks

Asier
 
S

Sami Vaaraniemi

Asier said:
Hello,

I've a webService thar read from my database and let results in a
SqlDataReader. I want to return this datreader to my ASP.NET page but it
fail.
This is my code:
***************************

Dim cnConexion As New SqlConnection("..................")

<WebMethod()> Public Function fLeerTodasCIAs() As SqlDataReader

Dim drCIAS As SqlDataReader

Dim cmd As New SqlCommand("spCIASLeerTodas", cnConexion)

cmd.CommandType = CommandType.StoredProcedure

cnConexion.Open()

drCIAS = cmd.ExecuteReader(CommandBehavior.CloseConnection)

drCIAS.Close()

End Function

**************************

What is the problem?? thanks

You cannot return an SqlDataReader from a Web service as an SqlDataReader is
not serializable over SOAP. Instead, return a DataSet or an array of custom
objects. For an example on how to return a DataSet, see:

http://msdn.microsoft.com/library/d.../html/cpconconsumingdatasetfromwebservice.asp

Regards,
Sami
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top