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

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...