Thursday, June 23, 2011

WCF : IMPORTANT : BE CAREFUL WHEN RETURNING A DATATABLE : ALWAYS NAME THE TABLE

If a web method in a wcf service is returning a DataTable, the DataTable must be given a name :


 
 Public Function ValidateUser(ByVal UserId As String, ByVal Password As String) As DataTable Implements ILoginService.ValidateUserDim retval As Boolean = FalseDim dtTemp As New DataTable("ReturnTable")Dim cmd As New SqlCommandcmd.CommandType =
cmd.CommandText =
CommandType.StoredProcedure"ValidateUser"cmd.Parameters.AddRange(
{

})
cmd.Connection =
cmd.Connection.Open()
dtTemp.Load(cmd.ExecuteReader())
cmd.Connection.Close()


New SqlParameter() _New SqlParameter("UserId", UserId), _New SqlParameter("Password", Password) _New SqlConnection(connstr)Return dtTempEnd Function



Other wise you may get an error something like this :

An existing connection was forcibly closed by the remote host



Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Dim dtTemp As New DataTable("ReturnTable")


No comments:

Post a Comment

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...