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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:11:28+00:00 2026-06-05T11:11:28+00:00

Good day. Please, help me about how to use three methods BeginExecuteReader() of SqlCommand

  • 0

Good day.

Please, help me about how to use three methods BeginExecuteReader() of SqlCommand class, using Generic Lists. I made a method using BeginExecuteReader, but i don’t know if this is the best way of usage

public class Empresa {
    public Empresa() {
        PkEmpresa = -1;
        CodigoEmpresa = "";
        Descripcion = "";
        PkCategoriaEmpresa = -1;
    }

    public int PkEmpresa { get; set; }
    public string CodigoEmpresa { get; set; }
    public string Descripcion { get; set; }
    public int PkCategoriaEmpresa { get; set; }

    public Empresa ShallowCopy() {
        return (Empresa)this.MemberwiseClone();
    }
}



public class AsyncronousDAL {
    private static string getConexion() {
        return "Data Source=DATABASE;Initial Catalog=DATA_BASE;Integrated Security=True;Asynchronous Processing=True";
    }

    public static List<Empresa> ConsultaAsincrona() {
        List<Empresa> _resultados = new List<Empresa>();

        using (SqlConnection conexion = new SqlConnection(getConexion())) {
            using (SqlCommand commando = new SqlCommand("[dbo].[pruebaAsync]", conexion)) {
                commando.CommandType = System.Data.CommandType.StoredProcedure;
                conexion.Open();
                IAsyncResult resultado = commando.BeginExecuteReader();
                using (SqlDataReader reader = commando.EndExecuteReader(resultado)) {
                    while (reader.Read()) {
                        _resultados.Add(new Empresa() {
                            PkEmpresa = Convert.ToInt32(reader["PkEmpresa"]),
                            CodigoEmpresa = reader["CodigoEmpresa"].ToString(),
                            Descripcion = reader["Descripcion"].ToString(),
                            PkCategoriaEmpresa = Convert.ToInt32(reader["PkCategoriaEmpresa"])
                        });
                    }
                }
            }
        }

        return _resultados;
    }
}
  • 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-06-05T11:11:31+00:00Added an answer on June 5, 2026 at 11:11 am

    If you aren’t familiar with the Asynch pattern there are lots of tutorials and examples on the web. This is old, but still relevant: http://msdn.microsoft.com/en-us/library/aa719595(v=vs.71).aspx

    When you call BeginExecuteReader that work is going to end up being pushed out to a worker thread, allowing your main to continue executing. When you call EndExecuteReader that will cause your main thread to block until that task is complete.

    If you immediately called EndExecuteReader – you aren’t really getting any benefit (in fact, you’re introducing additional overhead).

    Take a look at the example here: http://msdn.microsoft.com/en-us/library/7szdt0kc.aspx

    The BeginExecuteReader method returns immediately, but until the code
    executes the corresponding EndExecuteReader method call, it must not
    execute any other calls that start a synchronous or asynchronous
    execution against the same SqlCommand object. Calling the
    EndExecuteReader before the command’s execution is completed cause the
    SqlCommand object to block until the execution is finished.

    This is the relevant section of code:

                // Although it is not required that you pass the 
                // SqlCommand object as the second parameter in the 
                // BeginExecuteReader call, doing so makes it easier
                // to call EndExecuteReader in the callback procedure.
                AsyncCallback callback = new AsyncCallback(HandleCallback);
                command.BeginExecuteReader(callback, command);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day. I'm still learning GWT so please help me. I'm working on a
Good day! I am a newbie in php.. I made a form using html
Good day. I could really use your help on this one. I have a
Good day, could you please help me look and this code and tell me
Good day. Having read about Model 2 architecture I got confused about some points.
Good day everyone. I'm trying to figure out a way to use multiple flags
Good day. I'm confused about storing the embedded database in a Java EE application.
Good day everyone! I am using the T-SQL ISDATE() function with a date column
good day, I am using Joomla 1.5 and wanted to make a real estate
Good Day All, I’m new to programming. I’m using Visual Studio 2010. I’m taking

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.