Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is my code:

public List<Remarks1> fillRemarks1List(RemarksRequest oei)
{
    List<Remarks1> mylist = new List<Remarks1>();
    SqlConnection sqlConn = new SqlConnection(strConn);
    sqlConn.Open();
    SqlCommand commInfo = new SqlCommand();
    commInfo.CommandType = CommandType.StoredProcedure;
    commInfo.CommandText = "dbo.SPQueryRemList";
    commInfo.Connection = sqlConn;

    commInfo.Parameters.Add(new System.Data.SqlClient.SqlParameter("@reqNo", System.Data.SqlDbType.Char, 20));
    commInfo.Parameters["@reqNo"].Value = "0200000458";//oei.reqNo1.ToString().Trim();
    commInfo.Parameters.Add(new System.Data.SqlClient.SqlParameter("@lgnId", System.Data.SqlDbType.Char, 10));
    commInfo.Parameters["@lgnId"].Value = oei.loginid.ToString().Trim();

    SqlDataReader rdr4;
    try
    {
        rdr4 = commInfo.ExecuteReader();

        while (rdr4.Read())
        {
            mylist.Add(new Remarks1(rdr4.GetString(7).Trim(), rdr4.GetString(8).Trim(), rdr4.GetString(0).Trim(), rdr4.GetString(5).Trim()));
        }

        rdr4.Close();
    }
    catch (Exception ex)
    {

    }
    finally
    {
        commInfo.Dispose();

    }
    sqlConn.Close();

    return mylist;
}

IService:

[OperationContract]
[WebInvoke(Method = "POST",
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Wrapped,
    UriTemplate = "remarksList")]
List<Remarks1> fillRemarks1List(RemarksRequest oei);

The ajax call using my service:

urlToHandler = 'http://localhost/WcfService/Service1.svc/remarksList';

var tempyear="";

$.ajax({
    url: urlToHandler,
    data:JSON.stringify({oei:{"loginid":userid}}),
    type: 'POST',
    dataType:"json",
    contentType: 'application/json',
    success: function(data) {    
        alert(data.fillRemarksListResult);
        $.each(data.fillRemarksListResult,function(key,val) {
        });
    },
    error: function(data, status, jqXHR) {                       
        alert('There was an error.');
    }
}); // end $.ajax

I get the following errors:

rdr4.Depth threw an exception of type System.InvalidOperationException: Invalid attempt to call Depth when reader is closed.

rdr4.FieldCount threw an exception of type System.InvalidOperationException: Invalid attempt to call FieldCount when reader is closed.

rdr4.HasRows threw an exception of type System.InvalidOperationException: Invalid attempt to call HasRows when reader is closed.

Why?

share|improve this question
Please provide the details of those exceptions. There are messages that will describe why it's an invalid operation. – J. Steen Jan 25 at 6:31
It says: Invalid attempt to call depth when reader is closed Invalid attempt to call Fieldcount when reader is closed Invalid attempt to call Hasrows when reader is closed – Testing ur temper Jan 25 at 6:42
I'm not sure why you're getting those exceptions (the code doesn't look wrong to me), but do take a look at the using block in C#. It'll make dealing with the .Close()/.Dispose() stuff a lot easier. – Jason Malinowski Jan 25 at 6:52
or should i go for anyother collection classes ??? – Testing ur temper Jan 25 at 7:04

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.