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

  • Home
  • SEARCH
  • 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 5840209
In Process

The Archive Base Latest Questions

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

i try it in my .ashx page but i got error 500 in myXMLHttpRequest.status

  • 0

i try it in my .ashx page but i got error 500 in myXMLHttpRequest.status and i can’t understand where is the problem. a simple code for generate a simple xml would be very good. like:

<properties>
 <property>
   <address>812 Gwyn Ave</address>    
 </property>
 <property>
   <address>3308 James Ave S</address>    
 </property>
</properties>

@ here is my solution (sql code works fine):

public void ProcessRequest(HttpContext context)
    {
        context.Response.Clear();            
        context.Response.ContentType = "text/xml";
        XmlTextWriter writer = new XmlTextWriter();
        string user_id = context.Request.Params["user_id"];          

        string connectionString = ("Data Source=.;Initial Catalog=user_city;Integrated Security=True");
        string queryString = "select * from city_buildings where user_id=" + user_id + ";";
        using (SqlConnection connection = new SqlConnection(connectionString))
        {                
            SqlCommand command = new SqlCommand(queryString, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            writer.WriteStartDocument();
            try
            {               
                writer.WriteStartElement("buildings");
                while (reader.Read())
                {                        
                    writer.WriteStartElement("building");

                      writer.WriteElementString("user_id",Convert.ToString( reader[0]));

                    writer.WriteEndElement();

                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();
                writer.Close();
            }
            finally
            {                   
                reader.Close();
            }
        }
    }
  • 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:42:30+00:00Added an answer on May 22, 2026 at 11:42 am

    Dont have access to visual studio right now so doing this from top of the head. Should five you a starting point.

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/xml";
    
        using (XmlWriter writer = XmlWriter.Create(context.Response.OutputStream))
        {
            writer.WriteStartDocument();
            // do xmlwriter stuff here.
            writer.WriteEndDocument();
        }
    }
    

    Update:

    I indeed did mean to put OutputStream there. I updated the example to reflect this.

    Have been looking at your code briefly. I can see you do not output the result of the xmlwriter to the HttpResponse. (what my example does by binding it to Context.Response.OutputStream) That should be a reason why it won’t work. Altough why the 500 error occurs i don’t see. Maybe you should run in visual studio to see if any errors occur that will cause this.

    Also i noticed your use of reader[0]. Event tough this might technicly be correct i will suggest you use a safer method like the following:

    int fieldIndex = reader.GetOrdinal("address");
    reader.GetString(fieldIndex);
    

    This will ensure you will always get the desired field from the query. Even if in the future you decide to change the database schema to add some more columns.

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

Sidebar

Related Questions

I can run this code in Android app (using PhoneGap adn jQuery Mobile) but
Try as I might, I can't get a JNLP file to run locally (via
Try the following code: s = '#value#' puts s.gsub('#value#', Regexp.escape('*')) # => '\*' puts
try { // Code } catch (Exception ex) { Logger.Log(Message, ex); throw; } In
try{Integer.parse(Abhishek);} catch(NumberFormatException e){} catch(Exception e){} If for the above piece of code, if NumberFormatException
So I can call my IPN handling page (an aspx page) happily using Fiddler
I have an *.ashx (handler) with this code: public void ProcessRequest (HttpContext context) {
I'm using the shorthand AJAX call, $.get but when I try and reference a
Users on my site have a page they can write their own html to.
When i am displaying image from folder using Handler.ashx ans then try to save

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.