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 5838891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:30:59+00:00 2026-05-22T11:30:59+00:00

I am using JQuery to perform async calls to a WebService written in C#.

  • 0

I am using JQuery to perform async calls to a WebService written in C#. The WebService invokes a Stored Procedure (located in a SQL Server Database). The stored procedure returns results as XML (I use ‘for xml’ in the procedure to retrieve the result as XML).

The question is: How can I place the XML returned by the stored procedure (that is streamed by SQL Server) on to the HTTP Response stream of the WebService with the least amount of memory and processing time usage.

At the moment, my WebService returns XmlDocument object.I would like to know if there is a way to reduce the overhead of creation of XmlDocument or DataSet Objects, which consume both memory and processor time.

Ideal solution would be:
Connect the result stream pipe from SQL Server to the HTTP Response stream pipe. This way, whatever is coming from SQL Server will get to the client without the content being touched. No new objects are created (like DataSet, XmlDocument) and XmlParsing is avoided while creating XmlDocuments. Thus keeping the memory and processing footprint to the least. Also, whether the XML returned by the procedure is small or very large, since streams are used, memory usage will not grow (which is the case is XmlDocuments are created).

My reduced c# webservice method:

public XmlDocument GetXmlDataFromDB()
{
    string connStr = System.Convert.ToString(
            System.Web.Compilation.ConnectionStringsExpressionBuilder.GetConnectionString("DbConnectionString"),
            System.Globalization.CultureInfo.CurrentCulture);

    SqlConnection conn = new SqlConnection(connStr);
    SqlCommand sqlCmd = new SqlCommand("stp_GetXmlData", conn);
    sqlCmd.CommandType = CommandType.StoredProcedure;

    SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
    DataSet ds = new DataSet();
    conn.Open();

    XmlReader xmlReader = sqlCmd.ExecuteXmlReader();

    while (xmlReader.Read())
    {
        ds.ReadXml(xmlReader);
    }

    conn.Close();

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.InnerXml = ds.GetXml();

    return xmlDoc;
}

Any suggestions to improve the performance of the above code?

  • 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-22T11:30:59+00:00Added an answer on May 22, 2026 at 11:30 am

    In your code, you don’t need DataSet, SqlDataAdapter and InnerXml

    var doc = new XmlDocument();
    ...
    
    var reader = cmd.ExecuteXmlReader();
    if (reader.Read())
     doc.Load(reader);
    

    Alternatively you can use reader.ReadOuterXml() to get xml as string,without constructing a document.

    Also you can think of using WCF Services for ASP.NET AJAX

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery.get() to perform an AJAX call to a service. My service returns
I'd like to perform custom HTML transformations using jQuery for Wordpress posts database (sanify
I'm using jQuery to perform ajax callback and deal with lot of objects (over
I am using JQuery to perform form submission through an ajax request. I use
Using JQuery I am trying to perform validation and also get the values of
I am using jquery's change() to perform actions when SELECTs of a certain class
I'm using jQuery in an app which registers user clicks to perform a given
I am currently using JQuery to perform a single task: animation of width on
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I am using jQuery and in order to perform dynamic computations I need to

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.