Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:54:28+00:00 2026-05-25T05:54:28+00:00

I am noticing some odd behavior on my web page. I have a WCF

  • 0

I am noticing some odd behavior on my web page. I have a WCF Data service that serves up JSON to fill up a jqGrid. The service is called using javascript/ajax.

Then I have some server-side code that also calls the same WCF service to get data.

Inside my WCF Service I run cmd.ExecuteReader() without a prior open connection, and it doesn’t complain about the connection in certain cases — it seems to be when I’m calling the data service from javascript. However when I call the service from code-behind, ie server-side, I get the error that says “ExecuteReader requires an open and available connection”.

Does anyone know about this issue? Ive narrowed it down as much as possible. It appears the only difference is whether I call the service from client side or server side. Here is my code:

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class JsonService
{
    static String _connection = ConfigMgr.ConnectionStrings["MyConnStr"];
    static DomainEntities dbContext = new DomainEntities(_connection);

    [OperationContract]
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest,
                         RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    public JsonGrid Get()
    {
        return new JsonGridContract(dbContext.Products.ToJson()); 
    }
}

Below is where ExecuteReader() is called. It intercepts the provider, converts the expression tree to SQL, and then executes it parsing the results to string-based JSON rather than the domain objects.

    public static List<JsonRow> ToJson(this IQueryable queryable)
    {
        Expression expression = queryable.Expression;
        expression = Evaluator.PartialEval(expression);

        if !(queryable.Provider is JsonQueryProvider)
              throw new InvalidOperationException("Provider is invalid");

        String table = (queryable.Provider as JsonQueryProvider).Table; 

        SqlConnection connection = (queryable.Provider as JsonQueryProvider).Connection; 

        Type elementType = TypeSystem.GetElementType(expression.Type);

        TranslateResult result = new QueryTranslator(table).Translate(expression);

        SqlCommand cmd = connection.CreateCommand();

        cmd.CommandText = result.CommandText;

        SqlDataReader reader = cmd.ExecuteReader();

        List<JsonRow> jsonResult = new List<JsonRow>(); 

        while (reader.Read())
            {
                JsonRow instance = new JsonRow(reader.FieldCount); 

                for (int i = 0, n = reader.FieldCount; i < n; i++)
                {
                    var items = instance.Items; 

                    if (reader.IsDBNull(i))
                    {
                        items[i] = string.Empty;  
                    }
                    else
                    {
                        items[i] = reader[i].ToString(); 
                    }
                }

                jsonResult.Add(instance); 
            }

        reader.Close(); 

        return jsonResult; 
    }

As noted before this method executes fine even though I never open the connection. I am using AJAX client-side,

  $.ajax(
            {
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "Services/JsonService.svc/Get",
                data: {},
                dataType: "json",
                success: function (data, textStatus) {
                    if (textStatus == "success") {
                        var thegrid = $("#jqGrid")[0];
                        thegrid.addJSONData(data.d);
                    }
                },
                error: function (data, textStatus) {
                    alert('An error has occured retrieving data.');
                }
            });
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:54:29+00:00Added an answer on May 25, 2026 at 5:54 am

    First thing to exclude, is that you don’t dispose any of your objects.
    Your SqlCommand, SqlConnection, and SqlDataReader should all be in using stmt blocks.
    You don’t need your explicit close then. See if this then fails across the board. Im curious if its just that the garbage collector hasn’t collected yet to kill your connection object.

    using(SqlConnection connection = new SqlConnection(...))
    {
    ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a media streaming app, and noticing some odd behavior. Media stops
I'm noticing some behavior that I don't like, and I'm wondering if this is
I've an admin account under some team in apple. I noticing that I have
I have been noticing that some software engineering jobs are asking for .NET developers,
I have been noticing some very strange usage of O(1) in discussion of algorithms
This afternoon, upon noticing a broken build and the fact that some files looked
I have been noticing on my trackers that bots are visiting my site ALOT.
I am constantly noticing that I have files checked out for editing that I
I'm noticing some strange behavior when I add a ComboBox to my Windows Form
I'm noticing that some of the things that I do with images in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.